Skip to content

feat: add support for meta parameter in client paginated list queries#906

Merged
Kehrlann merged 2 commits intomodelcontextprotocol:mainfrom
smohite04:support-meta-list-tools
Apr 9, 2026
Merged

feat: add support for meta parameter in client paginated list queries#906
Kehrlann merged 2 commits intomodelcontextprotocol:mainfrom
smohite04:support-meta-list-tools

Conversation

@smohite04
Copy link
Copy Markdown
Contributor

@smohite04 smohite04 commented Apr 7, 2026

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 _meta in tools/list requests:

python
async def list_tools(self, *, cursor=None, meta=None) -> ListToolsResult

This change aligns the Java SDK with the Python SDK and the MCP spec which allows _meta in PaginatedRequestParams.

How Has This Been Tested?

  • Unit tests: McpAsyncClientTests.testListToolsWithCursorAndMeta() and testSyncListToolsWithCursorAndMeta() - verify _meta is correctly serialized in the JSON-RPC request
  • Integration test: AbstractMcpSyncClientTests.testListToolsWithMeta() - verified against the real server-everything MCP server via HttpClientStreamableHttpSyncClientTests (Docker/Testcontainers).

Ran per recommendations

Unit tests (McpAsyncClientTests):
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.467 s
  testListToolsWithCursorAndMeta    -- Time elapsed: 0.031 s  ✅
  testSyncListToolsWithCursorAndMeta -- Time elapsed: 0.006 s  ✅
  testListToolsWithEmptyCursor      -- Time elapsed: 0.360 s  ✅
  (+ 4 existing tests passing)
BUILD SUCCESS


Integration test (HttpClientStreamableHttpSyncClientTests against real 
server-everything via Docker):
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.59 s
  testListToolsWithMeta -- Time elapsed: 0.445 s  ✅
BUILD SUCCESS

Breaking Changes

None. New overloaded methods added; existing listTools(String cursor) behavior unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Closes #907

@smohite04 smohite04 marked this pull request as ready for review April 7, 2026 16:03
@Kehrlann Kehrlann self-assigned this Apr 8, 2026
@Kehrlann Kehrlann added P1 Significant bug affecting many users, highly requested feature enhancement New feature or request area/client waiting for user Waiting for user feedback or more details labels Apr 8, 2026
@Kehrlann
Copy link
Copy Markdown
Contributor

Kehrlann commented Apr 8, 2026

@smohite04 thank you for your contribution.

Could you please expand this to all paginated requests?

That is:

  • resources/list
  • resources/templates/list
  • prompts/list
  • tools/list

@smohite04
Copy link
Copy Markdown
Contributor Author

Thanks @Kehrlann. I will expand this to all paginated requests and update the PR shortly.

SHEETAL MOHITE 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
@smohite04 smohite04 force-pushed the support-meta-list-tools branch from cff0406 to 21c8fed Compare April 8, 2026 16:03
@smohite04
Copy link
Copy Markdown
Contributor Author

Extended support for remaining paginated requests.

Unit tests (McpAsyncClientTests):
Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.480 s
  testListToolsWithCursorAndMeta              ✅
  testSyncListToolsWithCursorAndMeta          ✅
  testListResourcesWithCursorAndMeta          ✅
  testSyncListResourcesWithCursorAndMeta      ✅
  testListResourceTemplatesWithCursorAndMeta   ✅
  testSyncListResourceTemplatesWithCursorAndMeta ✅
  testListPromptsWithCursorAndMeta            ✅
  testSyncListPromptsWithCursorAndMeta        ✅
  testListToolsWithEmptyCursor   ✅
  validateContextPassedToTransportConnect   ✅
  testCallToolWithOutputSchemaValidationSuccess   ✅
  testCallToolWithNoOutputSchemaSuccess   ✅
  testCallToolWithOutputSchemaValidationFailure   ✅
BUILD SUCCESS
Integration tests :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 12.72 s
  testListToolsWithMeta             ✅
  testListResourcesWithMeta         ✅
  testListResourceTemplatesWithMeta ✅
  testListPromptsWithMeta           ✅
BUILD SUCCESS

@Kehrlann Kehrlann changed the title feat: add support for meta parameter in listTools feat: add support for meta parameter in paginated list queries Apr 9, 2026
@Kehrlann Kehrlann changed the title feat: add support for meta parameter in paginated list queries feat: add support for meta parameter in client paginated list queries Apr 9, 2026
@Kehrlann Kehrlann self-requested a review April 9, 2026 08:37
Copy link
Copy Markdown
Contributor

@Kehrlann Kehrlann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
}
});
}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be factored into a reusable method.

@Kehrlann Kehrlann merged commit eaa0c69 into modelcontextprotocol:main Apr 9, 2026
21 checks passed
Kehrlann added a commit that referenced this pull request Apr 9, 2026
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>
Kehrlann added a commit that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client enhancement New feature or request P1 Significant bug affecting many users, highly requested feature waiting for user Waiting for user feedback or more details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add support for meta parameter to list tools call( paginated request already support meta field).

2 participants