Skip to content

Commit 032f61d

Browse files
committed
Update pagination.md
1 parent ce2a212 commit 032f61d

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

docs/specification/basic/utilities/pagination.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,44 @@ weight: 20
66
**Protocol Revision**: {{< param protocolRevision >}}
77
{{< /callout >}}
88

9-
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.
1012

1113
## Pagination Model
1214

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.
1416

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
1819

19-
## Request Format
20+
## Response Format
2021

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
2225

2326
```json
2427
{
2528
"jsonrpc": "2.0",
26-
"method": "resources/list",
27-
"params": {
28-
"cursor": "eyJwYWdlIjogMn0="
29+
"id": "123",
30+
"result": {
31+
"resources": [...],
32+
"nextCursor": "eyJwYWdlIjogM30="
2933
}
3034
}
3135
```
3236

33-
## Response Format
37+
## Request Format
3438

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:
3840

3941
```json
4042
{
4143
"jsonrpc": "2.0",
42-
"id": "123",
43-
"result": {
44-
"resources": [...],
45-
"nextCursor": "eyJwYWdlIjogM30="
44+
"method": "resources/list",
45+
"params": {
46+
"cursor": "eyJwYWdlIjogMn0="
4647
}
4748
}
4849
```
@@ -55,13 +56,13 @@ sequenceDiagram
5556
participant Server
5657
5758
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
6263
```
6364

64-
## Protocol Operations Supporting Pagination
65+
## Operations Supporting Pagination
6566

6667
The following MCP operations support pagination:
6768

@@ -72,21 +73,19 @@ The following MCP operations support pagination:
7273

7374
## Implementation Guidelines
7475

75-
1. Servers SHOULD:
76-
- Use consistent page sizes
76+
1. Servers **SHOULD**:
7777
- Provide stable cursors
7878
- Handle invalid cursors gracefully
7979

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
8382
- Support both paginated and non-paginated flows
8483

85-
3. Both parties MUST treat cursors as opaque tokens:
84+
3. Clients **MUST** treat cursors as opaque tokens:
8685
- Don't make assumptions about cursor format
8786
- Don't attempt to parse or modify cursors
8887
- Don't persist cursors across sessions
8988

9089
## Error Handling
9190

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

Comments
 (0)