feat: add support for meta parameter in client paginated list queries#906
Merged
Kehrlann merged 2 commits intomodelcontextprotocol:mainfrom Apr 9, 2026
Merged
Conversation
Contributor
|
@smohite04 thank you for your contribution. Could you please expand this to all paginated requests? That is:
|
Contributor
Author
|
Thanks @Kehrlann. I will expand this to all paginated requests and update the PR shortly. |
added 2 commits
April 8, 2026 08:16
…are: - resources/list - resources/templates/list - prompts/list - tools/list paginated list operations extended in this review: - listResources(String cursor, Map<String, Object> meta) - listResourceTemplates(String cursor, Map<String, Object> meta) - listPrompts(String cursor, Map<String, Object> meta) Closes modelcontextprotocol#907
cff0406 to
21c8fed
Compare
Contributor
Author
|
Extended support for remaining paginated requests. |
Kehrlann
approved these changes
Apr 9, 2026
Contributor
Kehrlann
left a comment
There was a problem hiding this comment.
Looks good. Minor details that I'll polish in a subsequent commit.
Thanks for your contribution!
| * @param meta Optional metadata to include in the request (_meta field) | ||
| * @return A Mono that emits the list of tools result | ||
| */ | ||
| public Mono<McpSchema.ListToolsResult> listTools(String cursor, java.util.Map<String, Object> meta) { |
Contributor
There was a problem hiding this comment.
I general, prefer imports over FQN
Comment on lines
+318
to
+367
| McpClientTransport transport = new McpClientTransport() { | ||
| Function<Mono<McpSchema.JSONRPCMessage>, Mono<McpSchema.JSONRPCMessage>> handler; | ||
|
|
||
| @Override | ||
| public Mono<Void> connect( | ||
| Function<Mono<McpSchema.JSONRPCMessage>, Mono<McpSchema.JSONRPCMessage>> handler) { | ||
| return Mono.deferContextual(ctx -> { | ||
| this.handler = handler; | ||
| return Mono.empty(); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<Void> closeGracefully() { | ||
| return Mono.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) { | ||
| if (!(message instanceof McpSchema.JSONRPCRequest request)) { | ||
| return Mono.empty(); | ||
| } | ||
|
|
||
| McpSchema.JSONRPCResponse response; | ||
| if (McpSchema.METHOD_INITIALIZE.equals(request.method())) { | ||
| response = new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), MOCK_INIT_RESULT, | ||
| null); | ||
| } | ||
| else if (McpSchema.METHOD_TOOLS_LIST.equals(request.method())) { | ||
| capturedRequest[0] = JSON_MAPPER.convertValue(request.params(), McpSchema.PaginatedRequest.class); | ||
| response = new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), mockToolsResult, | ||
| null); | ||
| } | ||
| else { | ||
| return Mono.empty(); | ||
| } | ||
|
|
||
| return handler.apply(Mono.just(response)).then(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T unmarshalFrom(Object data, TypeRef<T> typeRef) { | ||
| return JSON_MAPPER.convertValue(data, new TypeRef<>() { | ||
| @Override | ||
| public java.lang.reflect.Type getType() { | ||
| return typeRef.getType(); | ||
| } | ||
| }); | ||
| } | ||
| }; |
Contributor
There was a problem hiding this comment.
This should probably be factored into a reusable method.
Kehrlann
pushed a commit
that referenced
this pull request
Apr 9, 2026
…#906) * feat: add support for meta parameter in client paginated list queries# - resources/list - resources/templates/list - prompts/list - tools/list paginated list operations extended in this review: - listResources(String cursor, Map<String, Object> meta) - listResourceTemplates(String cursor, Map<String, Object> meta) - listPrompts(String cursor, Map<String, Object> meta) Closes #907 Co-authored-by: SHEETAL MOHITE <mohishee@amazon.com> Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Add support for meta parameter in listTools method.
Motivation and Context
McpSchema.PaginatedRequest now has a meta field (added in #344), but the client API methods don't expose it. As a result, servers which can accept the meta parameter in list tools cannot be used with java client. The Python SDK already supports passing
_metain tools/list requests:python
async def list_tools(self, *, cursor=None, meta=None) -> ListToolsResultThis change aligns the Java SDK with the Python SDK and the MCP spec which allows
_metain PaginatedRequestParams.How Has This Been Tested?
McpAsyncClientTests.testListToolsWithCursorAndMeta()andtestSyncListToolsWithCursorAndMeta()- verify_metais correctly serialized in the JSON-RPC requestAbstractMcpSyncClientTests.testListToolsWithMeta()- verified against the real server-everything MCP server via HttpClientStreamableHttpSyncClientTests (Docker/Testcontainers).Ran per recommendations
Breaking Changes
None. New overloaded methods added; existing listTools(String cursor) behavior unchanged.
Types of changes
Checklist
Additional context
Closes #907