Repository navigation
Conversation
## Motivation and Context `JSON.parse` with `symbolize_names: true` raises `EncodingError`, not `JSON::ParserError`, for an object key that is not valid UTF-8, since such a key cannot become a Symbol; the same bytes in a value are accepted. `StreamableHTTPTransport#parse_request_body`, `StdioTransport#parse_line` and `JsonRpcHandler.handle_json` rescued only the parser's own error. A sessionless modern POST is parsed from `handle_request` to tell the eras apart, before any rescue, so such a body raised out of the transport into the web server, whose error page then answered; a legacy POST answered 500 with the error reported, `handle_json` answered `-32603`, and over stdio the error raised out of `open` and ended the read loop. JSON text must be UTF-8 (RFC 8259, section 8.1), and the Python server refuses such a body as invalid JSON. The three now answer it as the parse error it is: `-32700`, over HTTP with 400 as for any other body that is not JSON. `handle_json` rescues the parse error around the parse only, so an error raised while handling keeps its own classification and a non-string input still answers `-32603`. The loop of `#send_request` that reads the client's reply rescues it the same way, so such a reply is reported as a parse failure before it fails the request, as an unparsable reply is. Over stdio on Ruby 3.2 and later, a frame holding such a byte is stopped earlier, by `String#strip` in the read loop; stripping frames as bytes is a separate change, and the stdio tests read their frames as bytes so that they cover the parse step alone. ## How Has This Been Tested? `test/json_rpc_handler_test.rb`, `test/mcp/server/transports/streamable_http_transport_test.rb` (a sessionless modern POST and a legacy `initialize`) and `test/mcp/server/transports/stdio_transport_test.rb`. Against the previous library the handler test gets `-32603`, the modern test raises `EncodingError`, the legacy test gets a 500 and the stdio test raises out of `open`. A client reply with such a key is reported as a parse failure; against the previous library it raises without the report. ## Breaking Changes None.
atesgoral
approved these changes
Oct 20, 2026
This branch has not been deployed
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
JSON.parsewithsymbolize_names: trueraisesEncodingError, notJSON::ParserError, for an object key that is not valid UTF-8, since such a key cannot become a Symbol; the same bytes in a value are accepted.StreamableHTTPTransport#parse_request_body,StdioTransport#parse_lineandJsonRpcHandler.handle_jsonrescued only the parser's own error. A sessionless modern POST is parsed fromhandle_requestto tell the eras apart, before any rescue, so such a body raised out of the transport into the web server, whose error page then answered; a legacy POST answered 500 with the error reported,handle_jsonanswered-32603, and over stdio the error raised out ofopenand ended the read loop. JSON text must be UTF-8 (RFC 8259, section 8.1), and the Python server refuses such a body as invalid JSON.The three now answer it as the parse error it is:
-32700, over HTTP with 400 as for any other body that is not JSON.handle_jsonrescues the parse error around the parse only, so an error raised while handling keeps its own classification and a non-string input still answers-32603.The loop of
#send_requestthat reads the client's reply rescues it the same way, so such a reply is reported as a parse failure before it fails the request, as an unparsable reply is. Over stdio on Ruby 3.2 and later, a frame holding such a byte is stopped earlier, byString#stripin the read loop; stripping frames as bytes is a separate change, and the stdio tests read their frames as bytes so that they cover the parse step alone.How Has This Been Tested?
test/json_rpc_handler_test.rb,test/mcp/server/transports/streamable_http_transport_test.rb(a sessionless modern POST and a legacyinitialize) andtest/mcp/server/transports/stdio_transport_test.rb. Against the previous library the handler test gets-32603, the modern test raisesEncodingError, the legacy test gets a 500 and the stdio test raises out ofopen. A client reply with such a key is reported as a parse failure; against the previous library it raises without the report.Breaking Changes
None.
Types of changes
Checklist