Reject listRoots if not supported by client, without sending any request #1067
Copy link
Copy link
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Some requests in McpAsyncServerExchange make a point of failing fast if functionality not supported, such the condition on line 146
java-sdk/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java
Lines 141 to 151 in fd00498
| public Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest) { | |
| if (this.clientCapabilities == null) { | |
| return Mono | |
| .error(new IllegalStateException("Client must be initialized. Call the initialize method first!")); | |
| } | |
| if (this.clientCapabilities.sampling() == null) { | |
| return Mono.error(new IllegalStateException("Client must be configured with sampling capabilities")); | |
| } | |
| return this.session.sendRequest(McpSchema.METHOD_SAMPLING_CREATE_MESSAGE, createMessageRequest, | |
| CREATE_MESSAGE_RESULT_TYPE_REF); | |
| } |
listRoots does not do the same
java-sdk/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java
Lines 227 to 230 in fd00498
| public Mono<McpSchema.ListRootsResult> listRoots(String cursor) { | |
| return this.session.sendRequest(McpSchema.METHOD_ROOTS_LIST, new McpSchema.PaginatedRequest(cursor), | |
| LIST_ROOTS_RESULT_TYPE_REF); | |
| } |
For example, add this
if (this.clientCapabilities.roots() == null) {
return Mono.error(new IllegalStateException("Client must be configured with root listing capabilities"));
} Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Activity
soyeladice-svg commentedon Sep 25, 2026
I reproduced this on current main at
c7fef64f92a99c8c758b1aa634f92868d7c2963b.A bounded local patch adding the missing initialized-client / roots-capability guard to
McpAsyncServerExchange.listRoots(String cursor), plus a regression test asserting that unsupported roots fail beforesession.sendRequest, passes the project's formatter and focusedMcpAsyncServerExchangeTests.I have not opened a PR yet because CONTRIBUTING asks that non-trivial changes be discussed first. If this scope matches what maintainers want for #1067, I can prepare the focused patch and run the broader required validation before submitting.
No production access or credentials were involved.
sushma3690 commentedon Oct 7, 2026
Hi, I have a fix for McpAsyncServerExchange.listRoots that mirrors the fast-fail capability checks already used by createMessage and createElicitation in the same class. The full mcp-core test suite passes with the change. I noticed PRs are already open for this issue. Before adding a sixth, could a maintainer confirm the desired scope and whether a new PR would help here, or whether you would prefer to pick up one of the existing ones?