Skip to content

Answer Invalid Params when tool or prompt arguments are not an object - #691

Open
yshmarov wants to merge 1 commit into
modelcontextprotocol:mainfrom
yshmarov:invalid-arguments-object
Open

yshmarov wants to merge 1 commit into
modelcontextprotocol:mainfrom
yshmarov:invalid-arguments-object

Conversation

@yshmarov

Copy link
Copy Markdown

tools/call with "arguments": "x" (or an array or a number) raised NoMethodError inside call_tool. The client got -32603 Internal error, and the server's exception_reporter received the NoMethodError as if it were a server bug. prompts/get did the same.

The MCP schema requires arguments to be an object, and JSON-RPC defines -32602 Invalid params for this. Both handlers now refuse a non-object value with RequestHandlerError and error_type: :invalid_params, as the unknown-tool case does. A missing arguments still works as before.

Reproduced on 1.10.0. The new tests fail on main and pass with the change. rake test and rake rubocop pass.

…bject

tools/call and prompts/get raised NoMethodError on a non-object
arguments value, so the client got -32603 Internal error and the
exception reporter saw a server fault for a client mistake.
Comment thread lib/mcp/server.rb
@@ -1424,6 +1424,12 @@ def call_tool(request, instrumentation_data:, session: nil, related_request_id:
end

arguments = request[:arguments] || {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One inconsistency is left: tools/call still accepts arguments: false, because request[:arguments] || {} turns it into {}, while prompts/get now refuses it.

Could tools/call fall back to {} only for an absent or null value, with a false case added to both tests?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants