Repository navigation
Handle a _meta that is not an object without raising - #650
Merged
Merged
Conversation
MCP requires `_meta` to be an object. When a request's `_meta` is a string, an array or a number, three `dig(:_meta, ...)` calls raised TypeError instead of answering a client error: - `validate_modern_headers` (Streamable HTTP, 2026-07-28): every method answered HTTP 500 -32603. `RequestEnvelope.parse!` already treats a non-object `_meta` as empty to answer -32602, but the header check runs first. - `call_tool`: legacy `tools/call` answered -32603 Internal error. - `build_server_context`: legacy `prompts/get` answered -32603. A non-object `_meta` carries no protocol version and no progress token, so these reads now skip it. The 2026-07-28 path answers HTTP 400 -32602, and legacy `tools/call` and `prompts/get` ignore the value, as legacy `tools/list` and `RequestEnvelope.modern?` already do.
7 of 9 tasks
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
MCP requires
_metato be an object, but a request whose_metais a string, an array or a numbermakes the server raise
TypeErrorfromdiginstead of answering a client error:MCP-Protocol-Version: 2026-07-28:validate_modern_headerscallsparams.dig(:_meta, ...), and the catch-all inhandle_modernanswers HTTP 500-32603for every method.RequestEnvelope.parse!already treats a non-object_metaas empty to answer-32602, but the header check runs first.call_toolandbuild_server_contextcalldig(:_meta, :progressToken),so
tools/callandprompts/getanswer-32603Internal error.tools/listalready ignores the value.A non-object
_metacarries no protocol version and no progress token, so these reads now skip it:-32602from envelope validation;tools/callandprompts/getignore it, astools/listdoes and asRequestEnvelope.modern?does.Similar to #609 / #616 (a malformed
Acceptmember answered 500).How Has This Been Tested?
test/mcp/server/transports/streamable_http_transport_test.rb: a modern POST with a string or array_metaanswers 400 with-32602.test/mcp/server_test.rb:tools/callandprompts/getwith a string or array_metarun normally.-32603"Internal error calling tool").rake testandrake rubocoppass.Breaking Changes
None. Requests with an object
_metaare handled as before. Only requests that raised now get a client error (2026-07-28) or are served (legacy).Types of changes
Checklist