Fix error behavior on unregistered handlers in stateless server handler (#800)

Instead of throwing an McpError, it now returns with a JSON-RPC method not found error (-32601), aligned with the stateful implementation.

Closes #784
This commit is contained in:
Mathias Geat 2026-07-08 14:42:06 +02:00 • committed by GitHub
commit 5d3decebd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,9 +32,9 @@ class DefaultMcpStatelessServerHandler implements McpStatelessServerHandler {
McpSchema.JSONRPCRequest request) {
McpStatelessRequestHandler<?> requestHandler = this.requestHandlers.get(request.method());
if (requestHandler == null) {
return Mono.error(McpError.builder(McpSchema.ErrorCodes.METHOD_NOT_FOUND)
.message("Missing handler for request type: " + request.method())
.build());
return Mono.just(new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), null,
new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.METHOD_NOT_FOUND,
"Method not found: " + request.method(), null)));
}
return requestHandler.handle(transportContext, request.params())
.map(result -> McpSchema.JSONRPCResponse.result(request.id(), result))