Read Complete Paginated MCP Tool and Resource Lists
Read list responses page by page, return nextCursor unchanged, and handle the end and invalid cursors.
Prerequisites and input · Engineering checks · 1. Pick the operation and send the first request
At a glance
Pagination in MCP 2025-06-18 uses opaque cursors rather than page numbers. The server decides the page size, and clients cannot assume a fixed length. For list responses that return nextCursor, this task describes how to decide first whether reading is finished, then pass the cursor back, and handle an invalid cursor while collecting a full catalog.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- MCP Read Complete Paginated MCP Tool and Resource Lists
Execution locations and responsibilities
- MCP client and server Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.
When to use
- A cursor is an opaque string that marks a position in the result set, and the server chooses the page size. Clients must treat it as an opaque token: make no assumptions about its format, do not parse or modify it, and do not persist it across sessions.
When not to use
- The page only says clients must not assume page size; it gives no size limit or cursor lifetime, so do not write specific numbers into the procedure.
- What to do after an invalid cursor, such as re-reading the catalog or how many retries, is not specified in the supplied text and is an implementer decision to record.
- This task covers paginated list reading only, not tool input schemas or call contracts.
Prerequisites and input
- The operation to read is one of the four that support pagination.
- The client loop can hold a cursor for the current session and tell normal completion from an error.
Engineering checks
Model layer: opaque cursor — A cursor is an opaque string that marks a position in the result set, and the server chooses the page size. Clients must treat it as an opaque token: make no assumptions about its format, do not parse or modify it, and do not persist it across sessions.
Message layer: response and request fields — A response carries the current page plus an optional nextCursor; to continue, the client puts that value in params.cursor of the next request. The operations that support pagination are resources/list, resources/templates/list, prompts/list and tools/list.
Termination layer: end and errors — A response without nextCursor should be treated as the end of results, which also covers a response that is not paginated at all. An invalid cursor should produce error code -32602 (Invalid params); servers should also provide stable cursors and handle invalid ones gracefully. Clients should support both paginated and non-paginated flows.
1. Pick the operation and send the first request
Where: the client's catalog reading logic. Input: one of the four list operations. Action: send the first request without a cursor. Completion check: the operation and session are recorded. Stop condition: if the operation is not on the pagination list, do not apply this procedure.
2. Store the page and check nextCursor
Where: the client's response parsing. Input: the most recent list response. Action: merge the page's items into the result without assuming its length, then check whether the response has nextCursor. Completion check: the page is stored and the presence or absence of nextCursor is noted. Stop condition: if the result field is missing or the structure is odd, stop and keep the raw response.
3. Finish reading when nextCursor is absent
Where: the loop's exit branch, evaluated before any new request is sent. Input: the check result from step two. Action: if nextCursor is absent, finish reading that operation; this also covers a first response that is not paginated. Completion check: the result set is closed and the recorded reason for ending is the missing nextCursor. Stop condition: do not infer the end from a short page or a smaller item count, since the server sets page size; continue to the next step only when nextCursor is present.
4. Pass nextCursor back unchanged and continue
Where: the client's next request. Input: the nextCursor from the previous response. Action: put it in params.cursor without decoding or editing, send the same operation again, then return to step two. Completion check: the sent value matches the received value character for character. Stop condition: if code parses or builds cursors, treat that as a violation and fix it first.
5. Handle an invalid cursor
Where: the error branch, which can fire after any continuation request. Input: a -32602 error and the cursor that was sent. Action: report it as invalid params, keep the partial results and mark them incomplete. Completion check: the record shows at which page reading broke. Stop condition: do not try to repair the cursor; whether to restart from the beginning is an implementer policy the page does not define, so document it separately.
6. Bound the cursor's lifetime
Where: session boundaries and caches. Input: cursors already used. Action: use them only within the current session and discard them when it ends. Completion check: no persistent store holds a cursor. Stop condition: when a new session begins, read again starting from a request with no cursor.
Task example
This is a hypothetical manual walkthrough, not a real run. Imagine a first tools/list request whose response includes nextCursor. The client stores the page, sees the field, and places the value unchanged in params.cursor for the next page; the second response has no such field, so the client finishes before sending anything else and merges both pages. In another imagined case a stale cursor is sent and the expected reply is -32602; the client records where it stopped and marks the result incomplete. These are expected observations and have not been verified.
Completion checks
- Transparency check: is each sent cursor identical to the one received, with no parsing or editing in the code?
- End check: after each stored page, does the client test for
nextCursorbefore deciding whether to send another request? - Error check: is -32602 handled on its own, with partial results flagged as incomplete?
Verification scope
Written only from the supplied Pagination page of the MCP 2025-06-18 specification. The documentation was read; installation, login, API execution and output were not tested.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.