You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Model Context Protocol (MCP) supports pagination for list operations that may return large result sets. Pagination allows clients to retrieve results in smaller chunks rather than all at once.
9
+
The Model Context Protocol (MCP) supports paginating list operations that may return large result sets. Pagination allows integrations to retrieve results in smaller chunks rather than all at once.
10
+
11
+
Pagination is especially important when connecting to external services over the internet, but also useful for local integrations to avoid performance issues with large data sets.
10
12
11
13
## Pagination Model
12
14
13
-
Pagination in MCP uses an opaque cursor-based approach. The key components are:
15
+
Pagination in MCP uses an opaque cursor-based approach, instead of numbered pages.
14
16
15
-
1.**Cursor**: An opaque string token representing a position in the result set
16
-
2.**Page Size**: Controlled by the server implementation
17
-
3.**Next Cursor**: Indicates if more results are available
17
+
* The **cursor** is an opaque string token, representing a position in the result set
18
+
***Page size** is determined by the server, and **MAY NOT** be fixed
18
19
19
-
## Request Format
20
+
## Response Format
20
21
21
-
Paginated requests can include an optional cursor parameter:
22
+
Pagination starts when the server sends a **response** that includes:
23
+
- The current page of results
24
+
- An optional `nextCursor` field if more results exist
22
25
23
26
```json
24
27
{
25
28
"jsonrpc": "2.0",
26
-
"method": "resources/list",
27
-
"params": {
28
-
"cursor": "eyJwYWdlIjogMn0="
29
+
"id": "123",
30
+
"result": {
31
+
"resources": [...],
32
+
"nextCursor": "eyJwYWdlIjogM30="
29
33
}
30
34
}
31
35
```
32
36
33
-
## Response Format
37
+
## Request Format
34
38
35
-
Paginated responses include:
36
-
- The current page of results
37
-
- An optional `nextCursor` field if more results exist
39
+
After receiving a cursor, the client can _continue_ paginating by issuing a request including that cursor:
38
40
39
41
```json
40
42
{
41
43
"jsonrpc": "2.0",
42
-
"id": "123",
43
-
"result": {
44
-
"resources": [...],
45
-
"nextCursor": "eyJwYWdlIjogM30="
44
+
"method": "resources/list",
45
+
"params": {
46
+
"cursor": "eyJwYWdlIjogMn0="
46
47
}
47
48
}
48
49
```
@@ -55,13 +56,13 @@ sequenceDiagram
55
56
participant Server
56
57
57
58
Client->>Server: List Request (no cursor)
58
-
Server-->>Client: First Page + nextCursor
59
-
Client->>Server: List Request (with cursor)
60
-
Server-->>Client: Next Page + nextCursor
61
-
Note over Client,Server: Repeat until no nextCursor
59
+
loop Pagination Loop
60
+
Server-->>Client: Page of results + nextCursor
61
+
Client->>Server: List Request (with cursor)
62
+
end
62
63
```
63
64
64
-
## Protocol Operations Supporting Pagination
65
+
## Operations Supporting Pagination
65
66
66
67
The following MCP operations support pagination:
67
68
@@ -72,21 +73,19 @@ The following MCP operations support pagination:
72
73
73
74
## Implementation Guidelines
74
75
75
-
1. Servers SHOULD:
76
-
- Use consistent page sizes
76
+
1. Servers **SHOULD**:
77
77
- Provide stable cursors
78
78
- Handle invalid cursors gracefully
79
79
80
-
2. Clients SHOULD:
81
-
- Store cursors for active pagination
82
-
- Handle missing nextCursor as end of results
80
+
2. Clients **SHOULD**:
81
+
- Treat a missing `nextCursor` as the end of results
83
82
- Support both paginated and non-paginated flows
84
83
85
-
3.Both parties MUST treat cursors as opaque tokens:
84
+
3.Clients **MUST** treat cursors as opaque tokens:
86
85
- Don't make assumptions about cursor format
87
86
- Don't attempt to parse or modify cursors
88
87
- Don't persist cursors across sessions
89
88
90
89
## Error Handling
91
90
92
-
Invalid cursor errors SHOULD be reported as standard JSON-RPC errors with code -32602 (Invalid params).
91
+
Invalid cursors **SHOULD** result in an error with code -32602 (Invalid params).
0 commit comments