Some requests in McpAsyncServerExchange make a point of failing fast if functionality not supported, such the condition on line 146
| publicMono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequestcreateMessageRequest) { |
| if (this.clientCapabilities == null) { |
| returnMono |
| .error(newIllegalStateException("Client must be initialized. Call the initialize method first!")); |
| } |
| if (this.clientCapabilities.sampling() == null) { |
| returnMono.error(newIllegalStateException("Client must be configured with sampling capabilities")); |
| } |
| returnthis.session.sendRequest(McpSchema.METHOD_SAMPLING_CREATE_MESSAGE, createMessageRequest, |
| CREATE_MESSAGE_RESULT_TYPE_REF); |
| } |
listRoots does not do the same
| publicMono<McpSchema.ListRootsResult> listRoots(Stringcursor) { |
| returnthis.session.sendRequest(McpSchema.METHOD_ROOTS_LIST, newMcpSchema.PaginatedRequest(cursor), |
| LIST_ROOTS_RESULT_TYPE_REF); |
| } |
For example, add this
if (this.clientCapabilities.roots() == null) { returnMono.error(newIllegalStateException("Client must be configured with root listing capabilities")); }
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
listRootsdoes not do the samejava-sdk/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java
Lines 227 to 230 in fd00498
For example, add this