Skip to main content
BlogAI

MCP Discovery Pagination Contract Tests

MCP discovery pagination lets a client enumerate a large catalogue over multiple list responses. See practical examples and verification steps.

Matthews Wong

Software Engineer

December 20262 min read
MCP Discovery Pagination Contract Tests

Key Takeaway

MCP discovery pagination lets a client enumerate a large catalogue over multiple list responses. A contract test should follow the server-provided cursor until the catalogue ends, then check for missing or repeated items. Test cursor errors and catalogue changes separately so the client can report them clearly.

How big should the fixture be?

Use one item more than your chosen page size to force the second page. Add an exact-boundary fixture so a terminal page can be checked separately. Stable item names make it easy to compare the returned order with expectations.

What can a client infer from a cursor?

Treat each cursor as opaque and pass it back as issued. Build the client loop around whether the response carries a continuation. Guessing a page number or deriving an offset from the token couples the client to one implementation.

How do we catch duplicated entries?

Collect all names and assert both the count and the expected set. A count alone can pass when a duplicate replaces a missing tool. Use an ordinary catalogue without live updates for this baseline check.

What should happen after a cursor fails?

Record the server response for an expired or invalid cursor. A client can restart discovery when its design supports that recovery, and it should replace the partial catalogue on restart. Assert what the reader sees while the refreshed list loads.

How should catalogue updates be handled?

Change the list between two pages in a dedicated test. Compare what the implementation promises with what it returns, such as continuing a snapshot or signalling a refresh. Document the behaviour clients should expect before relying on it.

What evidence belongs in a pull request?

Show fixture size, responses per page and the final expected set. Include one failing cursor example and the observed recovery. This gives a reviewer enough information to tell whether a list screenshot represents the whole catalogue.

FAQ

Frequently Asked Questions

Short answers to what readers ask most about this topic.

How big should the fixture be?

Use one item more than your chosen page size to force the second page. Add an exact-boundary fixture so a terminal page can be checked separately. Stable item names make it easy to compare the returned order with expectations.

What can a client infer from a cursor?

Treat each cursor as opaque and pass it back as issued. Build the client loop around whether the response carries a continuation. Guessing a page number or deriving an offset from the token couples the client to one implementation.

How do we catch duplicated entries?

Collect all names and assert both the count and the expected set. A count alone can pass when a duplicate replaces a missing tool. Use an ordinary catalogue without live updates for this baseline check.

What should happen after a cursor fails?

Record the server response for an expired or invalid cursor. A client can restart discovery when its design supports that recovery, and it should replace the partial catalogue on restart. Assert what the reader sees while the refreshed list loads.

How should catalogue updates be handled?

Change the list between two pages in a dedicated test. Compare what the implementation promises with what it returns, such as continuing a snapshot or signalling a refresh. Document the behaviour clients should expect before relying on it.