Return JSON-RPC protocol errors for unknown tool calls

Per the MCP specification, an unknown tool call is a protocol-level error, not a tool execution error.
Return JSON-RPC -32602 (Invalid params) instead of successful responses with `isError: true`.
https://modelcontextprotocol.io/specification/2025-11-25/server/tools#error-handling

Fixes #228.
This commit is contained in:
Koichi ITO 2026-02-19 02:51:11 +09:00
commit 15710ef0aa

View file

@ -377,7 +377,7 @@ module MCP
unless tool
add_instrumentation_data(tool_name: tool_name, error: :tool_not_found)
return error_tool_response("Tool not found: #{tool_name}")
raise RequestHandlerError.new("Tool not found: #{tool_name}", request, error_type: :invalid_params)
end
arguments = request[:arguments] || {}
@ -401,6 +401,8 @@ module MCP
end
call_tool_with_args(tool, arguments)
rescue RequestHandlerError
raise
rescue => e
report_exception(e, request: request)