Skip to content

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

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yshmarov:invalid-arguments-object
Nov 21, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
yshmarov:invalid-arguments-object

Conversation

@yshmarov

Copy link
Copy Markdown
Contributor

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.

Comment thread lib/mcp/server.rb Outdated
@@ -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?

@koic

koic commented Nov 20, 2026

Copy link
Copy Markdown
Member

@yshmarov Looks good to me. Can you squash your commits into one?

…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.
@koic
koic force-pushed the invalid-arguments-object branch from 2b8fe07 to 5cc3776 Compare November 21, 2026 07:55
@koic
koic merged commit 86f1f68 into modelcontextprotocol:main Nov 21, 2026
13 checks passed
koic added a commit to koic/ruby-sdk that referenced this pull request Nov 21, 2026
## Motivation and Context

modelcontextprotocol#691 answers `-32602` when the `arguments` of `tools/call` or `prompts/get` is not an object. The same kind of
client mistake still surfaced as `-32603` Internal error, with a `TypeError` or `NoMethodError` handed
to the exception reporter as if the server had failed, in these places:

- `tools/call`, `prompts/get` and `logging/setLevel` with `params` that is an array, or absent. JSON-RPC allows
  positional params, so the request reaches the handler, which reads a named member.
- `completion/complete` with a `ref` or an `argument` that is not an object.

All of them are now refused with `-32602` Invalid params before the handler, the tool or the prompt runs,
as `resources/read` and `resources/subscribe` already are. An absent or `null` `arguments` still stands for none.

Resolves modelcontextprotocol#694.

The issue also asks that such a refusal stay out of the exception reporter. That is not taken: the SDK reports
a request its handlers refuse, an unknown tool as much as these, and what the reporter receives is now a `RequestHandlerError`
whose `error_type` is `:invalid_params`, in place of the `TypeError` or `NoMethodError`.

## How Has This Been Tested?

`test/mcp/server_test.rb`; two of the three new tests fail on the previous library, and the third holds that
absent and `null` arguments keep working.

## Breaking Changes

None for a request that follows the schema.
koic added a commit to koic/ruby-sdk that referenced this pull request Nov 21, 2026
## Motivation and Context

modelcontextprotocol#691 answers `-32602` when the `arguments` of `tools/call` or `prompts/get` is not an object. The same kind of
client mistake still surfaced as `-32603` Internal error, with a `TypeError` or `NoMethodError` handed
to the exception reporter as if the server had failed, in these places:

- `tools/call`, `prompts/get` and `logging/setLevel` with `params` that is an array, or absent. JSON-RPC allows
  positional params, so the request reaches the handler, which reads a named member.
- `completion/complete` with a `ref` or an `argument` that is not an object.

All of them are now refused with `-32602` Invalid params before the handler, the tool or the prompt runs,
as `resources/read` and `resources/subscribe` already are. An absent or `null` `arguments` still stands for none.

Resolves modelcontextprotocol#694.

The issue also asks that such a refusal stay out of the exception reporter. That is not taken: the SDK reports
a request its handlers refuse, an unknown tool as much as these, and what the reporter receives is now a `RequestHandlerError`
whose `error_type` is `:invalid_params`, in place of the `TypeError` or `NoMethodError`.

## How Has This Been Tested?

`test/mcp/server_test.rb`; two of the three new tests fail on the previous library, and the third holds that
absent and `null` arguments keep working.

## Breaking Changes

None for a request that follows the schema.
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