Conversation
yuki3738
force-pushed
the
validate_required_resources_read_params
branch
from
September 12, 2026 08:23
894448f to
8ab6a6f
Compare
## Motivation and Context The MCP schema requires a string `uri` in `resources/read` params. The server dispatched the request without checking it, and the outcome depended on how the read was served. A custom `resources_read_handler` received the params unchanged, so a handler that echoes `params[:uri]` answered with a success result carrying `null`. The class-based router raised a `TypeError` on a non-string `uri` once a resource template was registered, which surfaced as `-32603` Internal error. Both now return `-32602` Invalid params, matching the check modelcontextprotocol#451 added for `initialize` and `resources/subscribe`. The check runs before dispatch, so it covers custom handlers and the class-based router alike. This change validates that `uri` is present and is a string. It does not validate URI syntax: that needs a separate change, weighing what to reject against the risk to existing clients. ## How Has This Been Tested? Added tests for `params` absent, `params` that are not an object, `uri` absent, and a non-string `uri`. The non-string case is covered with a class-based resource and with a class-based template registered, since only the template path reached the `TypeError`. A further test asserts that a custom `resources_read_handler` never runs when `uri` is missing. Also verified by hand over `Server#handle_json` that each of these requests now answers `-32602`. ## Breaking Changes A `resources/read` request without `uri`, or with a non-string `uri`, now receives `-32602` Invalid params. Earlier releases passed such a request to the handler, which could answer it successfully, or raised `-32603` Internal error from the class-based router. Such requests violate the MCP schema, and a valid string `uri` is unaffected.
yuki3738
force-pushed
the
validate_required_resources_read_params
branch
from
September 12, 2026 08:36
8ab6a6f to
8d64b59
Compare
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. The server dispatched the request without checking it, and the outcome depended on how the read was served. A customresources_read_handlerreceived the params unchanged, so a handler that echoesparams[:uri]answered with a success result carryingnull. The class-based router raised aTypeErroron a non-stringurionce a resource template was registered, which surfaced as-32603Internal error. Both now return-32602Invalid params, matching the check modelcontextprotocol#451 added forinitializeandresources/subscribe. The check runs before dispatch, so it covers custom handlers and the class-based router alike.This change validates that
uriis present and is a string. It does not validate URI syntax: that needs a separate change, weighing what to reject against the risk to existing clients.Before, with a
resources_read_handlerthat echoesparams[:uri]:Before, with a class-based resource template registered:
After, for every case above:
How Has This Been Tested?
Added tests for
paramsabsent,paramsthat are not an object,uriabsent, and a non-stringuri. The non-string case is covered with a class-based resource and with a class-based template registered, since only the template path reached theTypeError. A further test asserts that a customresources_read_handlernever runs whenuriis missing. Also verified by hand overServer#handle_jsonthat each of these requests now answers-32602.rake testpasses (1784 runs, 0 failures).Breaking Changes
A
resources/readrequest withouturi, or with a non-stringuri, now receives-32602Invalid params. Earlier releases passed such a request to the handler, which could answer it successfully, or raised-32603Internal error from the class-based router. Such requests violate the MCP schema, and a valid stringuriis unaffected.Types of changes
Checklist