feat: add paginated list decorators for prompts, resources, and tools#1286
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds pagination support for listing prompts, resources, and tools using cursor-based pagination as defined in the MCP spec.
The lowlevel Server decorators
list_resources,list_prompts, andlist_toolsnow handle two types of handlers:Callable[[], Awaitable[list[<resource, prompt, or tool>]]]Callable[[List<___>Request], Awaitable[List<___>Result]]List<___>Requestobject depending on the decorator which the handle can now optionally handle.List<___>Responsewhich the handler can specify the cursor for the next page.How It Works
The decorators now automatically detect whether a callback accepts a cursor parameter:
Changes
list_prompts(),list_resources(), andlist_tools()decorators to support both signaturesTest plan
🤖 Generated with Claude Code
👨 Below generated by the human, Max Isbey
Manual testing
I spun up the MCP inspector and ran the example pagination server in both stdio mode and SSE mode. Below is some testing evidence using the SSE mode:
Clicking "List More Resources" correctly lists all 30 resources:
Note: this works for prompts and tools as well
Requesting a resource works:
Running the pagination client example code works listing all 30 resources: