Repository navigation
Conversation
## Motivation and Context The MCP schema requires a string `uri` in `resources/read` params, but the server dispatched the request without checking it, so the outcome depended on how the read was served: - A custom `resources_read_handler` received the params unchanged. A handler that echoes `params[:uri]` answered successfully with a `null` or non-string `uri`. - With a class-based resource template registered, a non-string `uri` such as `123` raised a `TypeError`, which surfaced as `-32603` Internal error. - Absent, `null`, or array `params` surfaced as `-32603` from the class-based router or from a handler that reads them. These requests now return `-32602` Invalid params before dispatch, matching the check modelcontextprotocol#451 added for `initialize` and `resources/subscribe`. `tools/call` and `prompts/get` already return `-32602` when `name` is missing. The check covers custom handlers and the class-based router, on both the `initialize`-based lifecycle and the 2026-07-28 `_meta` envelope lifecycle. Requests that already answered `-32602` with `Resource not found`, such as a `null` URI on the class-based router, now report `Invalid params`. URI syntax is not validated. That needs a separate change, weighing what to reject against the risk to existing clients. ## How Has This Been Tested? Added tests that absent or array `params`, and an absent, `null`, or non-string `uri`, return `-32602` across the custom handler, class-based resource, and class-based template paths. Further tests assert that a custom handler never runs when `uri` is missing or is not a string, including on a 2026-07-28 request. ## Breaking Changes Over JSON-RPC, only requests that violate the MCP schema change: they now receive `-32602` Invalid params instead of a success, `-32603`, or `Resource not found`. Calling `Server#handle` from Ruby with string-keyed params such as `{ "uri" => "file:///a" }` is now refused, as the class-based router and the `resources/subscribe` check already expect symbol keys. `Server#handle_json` symbolizes keys, so this key-type restriction does not affect requests sent as JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
The MCP schema requires a string
uriinresources/readparams, but the server dispatched the request without checking it, so the outcome depended on how the read was served:resources_read_handlerreceived the params unchanged. A handler that echoesparams[:uri]answered successfully with anullor non-stringuri.urisuch as123raised aTypeError, which surfaced as-32603Internal error.null, or arrayparamssurfaced as-32603from the class-based router or from a handler that reads them.These requests now return
-32602Invalid params before dispatch, matching the check #451 added forinitializeandresources/subscribe.tools/callandprompts/getalready return-32602whennameis missing. The check covers custom handlers and the class-based router, on both theinitialize-based lifecycle and the 2026-07-28_metaenvelope lifecycle. Requests that already answered-32602withResource not found, such as anullURI on the class-based router, now reportInvalid params.URI syntax is not validated. That needs a separate change, weighing what to reject against the risk to existing clients.
How Has This Been Tested?
Added tests that absent or array
params, and an absent,null, or non-stringuri, return-32602across the custom handler, class-based resource, and class-based template paths. Further tests assert that a custom handler never runs whenuriis missing or is not a string, including on a 2026-07-28 request.rake testpasses (2694 runs, 0 failures).Breaking Changes
Over JSON-RPC, only requests that violate the MCP schema change: they now receive
-32602Invalid params instead of a success,-32603, orResource not found. CallingServer#handlefrom Ruby with string-keyed params such as{ "uri" => "file:///a" }is now refused, as the class-based router and theresources/subscribecheck already expect symbol keys.Server#handle_jsonsymbolizes keys, so this key-type restriction does not affect requests sent as JSON.Types of changes
Checklist