Validate Required Params for initialize and resources/subscribe#451
Merged
koic merged 1 commit intoJul 11, 2026
Conversation
## Motivation and Context Fixes modelcontextprotocol#450 The MCP schema requires `protocolVersion`, `capabilities`, and `clientInfo` on `initialize` params, and `uri` on `resources/subscribe` and `resources/unsubscribe` params. The server accepted requests with these fields absent: `initialize` silently negotiated the server's default protocol version, and `resources/subscribe` returned an empty success result. Both now return `-32602` Invalid params, matching the Python SDK, which rejects such requests during pydantic validation. The `uri` check runs before dispatch so it also covers handlers registered via `resources_subscribe_handler` and `resources_unsubscribe_handler`. A `protocolVersion` value that is present but unsupported still negotiates the server's fallback version, as the spec's lifecycle section requires. ## How Has This Been Tested? Reproduced the issue's stdio repro steps: both malformed requests now return `-32602` instead of succeeding. ## Breaking Changes Clients that send `initialize` without `protocolVersion`, `capabilities`, or `clientInfo`, or `resources/subscribe` / `resources/unsubscribe` without `uri`, now receive `-32602` Invalid params instead of a success response. Such requests violate the MCP schema, but any code relying on the previous lenient behavior (for example, test harnesses sending bare `initialize` requests) must now include the required fields.
atesgoral
approved these changes
Jul 11, 2026
9 tasks
koic
added a commit
that referenced
this pull request
Jul 11, 2026
## Motivation and Context `bundle exec rake` fails on main with four errors in `streamable_http_transport_test.rb`: ``` NoMethodError: undefined method '[]=' for nil streamable_http_transport_test.rb:5119 (install_mutex_probe_stream) ``` This is a semantic conflict between two merged PRs. #451 made the server reject `initialize` requests that lack the required `protocolVersion`, `capabilities`, and `clientInfo` params with -32602. #449, merged after but developed before it, added the "writes outside the mutex" tests, whose `initialize_test_session` helper sends an `initialize` request with no params. That request is now rejected, no session is created, so `@sessions[session_id]` is nil and installing the probe stream raises `NoMethodError`. The fix adds `params: initialize_params` to the helper's request body, matching the pattern used by every other `initialize` request in the file via `InitializeParamsTestHelper`. ## How Has This Been Tested? `bundle exec rake` now passes: 1318 runs, 0 failures, 0 errors, and RuboCop reports no offenses. The four previously failing tests are the regression coverage. ## Breaking Changes None. Test-only change.
koic
added a commit
to rubocop/rubocop
that referenced
this pull request
Jul 12, 2026
The mcp gem 0.24.0 validates required params for the `initialize` request per the MCP schema and returns a `-32602` Invalid params error when `protocolVersion`, `capabilities`, or `clientInfo` is missing: modelcontextprotocol/ruby-sdk#451 The MCP specs sent bare `initialize` requests without params, relying on the previous lenient behavior, so they started failing once CI picked up mcp 0.24.0. The RuboCop MCP server itself is unaffected because real clients send these required fields. This makes the spec requests conform to the MCP schema.
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
Fixes #450
The MCP schema requires
protocolVersion,capabilities, andclientInfooninitializeparams, andurionresources/subscribeandresources/unsubscribeparams. The server accepted requests with these fields absent:initializesilently negotiated the server's default protocol version, andresources/subscribereturned an empty success result. Both now return-32602Invalid params, matching the Python SDK, which rejects such requests during pydantic validation. Theuricheck runs before dispatch so it also covers handlers registered viaresources_subscribe_handlerandresources_unsubscribe_handler.A
protocolVersionvalue that is present but unsupported still negotiates the server's fallback version, as the spec's lifecycle section requires.How Has This Been Tested?
Reproduced the issue's stdio repro steps: both malformed requests now return
-32602instead of succeeding.Breaking Changes
Clients that send
initializewithoutprotocolVersion,capabilities, orclientInfo, orresources/subscribe/resources/unsubscribewithouturi, now receive-32602Invalid params instead of a success response. Such requests violate the MCP schema, but any code relying on the previous lenient behavior (for example, test harnesses sending bareinitializerequests) must now include the required fields.Types of changes
Checklist