Skip to content

Commit 84c5e97

Browse files
Merge pull request modelcontextprotocol#21 from modelcontextprotocol/justin/pagination
Pagination
2 parents 272d107 + f764f4f commit 84c5e97

File tree

2 files changed

+152
-40
lines changed

2 files changed

+152
-40
lines changed

schema/schema.json

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@
345345
],
346346
"type": "object"
347347
},
348+
"Cursor": {
349+
"description": "An opaque token used to represent a cursor for pagination.",
350+
"type": "string"
351+
},
348352
"EmptyResult": {
349353
"$ref": "#/definitions/Result"
350354
},
@@ -678,16 +682,10 @@
678682
"type": "string"
679683
},
680684
"params": {
681-
"additionalProperties": {},
682685
"properties": {
683-
"_meta": {
684-
"properties": {
685-
"progressToken": {
686-
"$ref": "#/definitions/ProgressToken",
687-
"description": "If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications."
688-
}
689-
},
690-
"type": "object"
686+
"cursor": {
687+
"description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.",
688+
"type": "string"
691689
}
692690
},
693691
"type": "object"
@@ -706,6 +704,10 @@
706704
"description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.",
707705
"type": "object"
708706
},
707+
"nextCursor": {
708+
"description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.",
709+
"type": "string"
710+
},
709711
"prompts": {
710712
"items": {
711713
"$ref": "#/definitions/Prompt"
@@ -718,24 +720,18 @@
718720
],
719721
"type": "object"
720722
},
721-
"ListResourcesRequest": {
722-
"description": "Sent from the client to request a list of resources the server has.",
723+
"ListResourceTemplatesRequest": {
724+
"description": "Sent from the client to request a list of resource templates the server has.",
723725
"properties": {
724726
"method": {
725-
"const": "resources/list",
727+
"const": "resources/templates/list",
726728
"type": "string"
727729
},
728730
"params": {
729-
"additionalProperties": {},
730731
"properties": {
731-
"_meta": {
732-
"properties": {
733-
"progressToken": {
734-
"$ref": "#/definitions/ProgressToken",
735-
"description": "If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications."
736-
}
737-
},
738-
"type": "object"
732+
"cursor": {
733+
"description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.",
734+
"type": "string"
739735
}
740736
},
741737
"type": "object"
@@ -746,19 +742,63 @@
746742
],
747743
"type": "object"
748744
},
749-
"ListResourcesResult": {
750-
"description": "The server's response to a resources/list request from the client.",
745+
"ListResourceTemplatesResult": {
746+
"description": "The server's response to a resources/templates/list request from the client.",
751747
"properties": {
752748
"_meta": {
753749
"additionalProperties": {},
754750
"description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.",
755751
"type": "object"
756752
},
753+
"nextCursor": {
754+
"description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.",
755+
"type": "string"
756+
},
757757
"resourceTemplates": {
758758
"items": {
759759
"$ref": "#/definitions/ResourceTemplate"
760760
},
761761
"type": "array"
762+
}
763+
},
764+
"required": [
765+
"resourceTemplates"
766+
],
767+
"type": "object"
768+
},
769+
"ListResourcesRequest": {
770+
"description": "Sent from the client to request a list of resources the server has.",
771+
"properties": {
772+
"method": {
773+
"const": "resources/list",
774+
"type": "string"
775+
},
776+
"params": {
777+
"properties": {
778+
"cursor": {
779+
"description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.",
780+
"type": "string"
781+
}
782+
},
783+
"type": "object"
784+
}
785+
},
786+
"required": [
787+
"method"
788+
],
789+
"type": "object"
790+
},
791+
"ListResourcesResult": {
792+
"description": "The server's response to a resources/list request from the client.",
793+
"properties": {
794+
"_meta": {
795+
"additionalProperties": {},
796+
"description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.",
797+
"type": "object"
798+
},
799+
"nextCursor": {
800+
"description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.",
801+
"type": "string"
762802
},
763803
"resources": {
764804
"items": {
@@ -767,6 +807,9 @@
767807
"type": "array"
768808
}
769809
},
810+
"required": [
811+
"resources"
812+
],
770813
"type": "object"
771814
},
772815
"ListToolsRequest": {
@@ -777,16 +820,10 @@
777820
"type": "string"
778821
},
779822
"params": {
780-
"additionalProperties": {},
781823
"properties": {
782-
"_meta": {
783-
"properties": {
784-
"progressToken": {
785-
"$ref": "#/definitions/ProgressToken",
786-
"description": "If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications."
787-
}
788-
},
789-
"type": "object"
824+
"cursor": {
825+
"description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.",
826+
"type": "string"
790827
}
791828
},
792829
"type": "object"
@@ -805,6 +842,10 @@
805842
"description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.",
806843
"type": "object"
807844
},
845+
"nextCursor": {
846+
"description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.",
847+
"type": "string"
848+
},
808849
"tools": {
809850
"items": {
810851
"$ref": "#/definitions/Tool"
@@ -883,6 +924,40 @@
883924
],
884925
"type": "object"
885926
},
927+
"PaginatedRequest": {
928+
"properties": {
929+
"method": {
930+
"type": "string"
931+
},
932+
"params": {
933+
"properties": {
934+
"cursor": {
935+
"description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.",
936+
"type": "string"
937+
}
938+
},
939+
"type": "object"
940+
}
941+
},
942+
"required": [
943+
"method"
944+
],
945+
"type": "object"
946+
},
947+
"PaginatedResult": {
948+
"properties": {
949+
"_meta": {
950+
"additionalProperties": {},
951+
"description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.",
952+
"type": "object"
953+
},
954+
"nextCursor": {
955+
"description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.",
956+
"type": "string"
957+
}
958+
},
959+
"type": "object"
960+
},
886961
"PingRequest": {
887962
"description": "A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.",
888963
"properties": {

schema/schema.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export const JSONRPC_VERSION = "2.0";
1212
*/
1313
export type ProgressToken = string | number;
1414

15+
/**
16+
* An opaque token used to represent a cursor for pagination.
17+
*/
18+
export type Cursor = string;
19+
1520
export interface Request {
1621
method: string;
1722
params?: {
@@ -245,20 +250,52 @@ export interface ProgressNotification extends Notification {
245250
};
246251
}
247252

253+
/* Pagination */
254+
export interface PaginatedRequest extends Request {
255+
params?: {
256+
/**
257+
* An opaque token representing the current pagination position.
258+
* If provided, the server should return results starting after this cursor.
259+
*/
260+
cursor?: Cursor;
261+
};
262+
}
263+
264+
export interface PaginatedResult extends Result {
265+
/**
266+
* An opaque token representing the pagination position after the last returned result.
267+
* If present, there may be more results available.
268+
*/
269+
nextCursor?: Cursor;
270+
}
271+
248272
/* Resources */
249273
/**
250274
* Sent from the client to request a list of resources the server has.
251275
*/
252-
export interface ListResourcesRequest extends Request {
276+
export interface ListResourcesRequest extends PaginatedRequest {
253277
method: "resources/list";
254278
}
255279

256280
/**
257281
* The server's response to a resources/list request from the client.
258282
*/
259-
export interface ListResourcesResult extends Result {
260-
resourceTemplates?: ResourceTemplate[];
261-
resources?: Resource[];
283+
export interface ListResourcesResult extends PaginatedResult {
284+
resources: Resource[];
285+
}
286+
287+
/**
288+
* Sent from the client to request a list of resource templates the server has.
289+
*/
290+
export interface ListResourceTemplatesRequest extends PaginatedRequest {
291+
method: "resources/templates/list";
292+
}
293+
294+
/**
295+
* The server's response to a resources/templates/list request from the client.
296+
*/
297+
export interface ListResourceTemplatesResult extends PaginatedResult {
298+
resourceTemplates: ResourceTemplate[];
262299
}
263300

264301
/**
@@ -433,14 +470,14 @@ export interface BlobResourceContents extends ResourceContents {
433470
/**
434471
* Sent from the client to request a list of prompts and prompt templates the server has.
435472
*/
436-
export interface ListPromptsRequest extends Request {
473+
export interface ListPromptsRequest extends PaginatedRequest {
437474
method: "prompts/list";
438475
}
439476

440477
/**
441478
* The server's response to a prompts/list request from the client.
442479
*/
443-
export interface ListPromptsResult extends Result {
480+
export interface ListPromptsResult extends PaginatedResult {
444481
prompts: Prompt[];
445482
}
446483

@@ -519,14 +556,14 @@ export interface PromptListChangedNotification extends Notification {
519556
/**
520557
* Sent from the client to request a list of tools the server has.
521558
*/
522-
export interface ListToolsRequest extends Request {
559+
export interface ListToolsRequest extends PaginatedRequest {
523560
method: "tools/list";
524561
}
525562

526563
/**
527564
* The server's response to a tools/list request from the client.
528565
*/
529-
export interface ListToolsResult extends Result {
566+
export interface ListToolsResult extends PaginatedResult {
530567
tools: Tool[];
531568
}
532569

0 commit comments

Comments
 (0)