Repository navigation
Strip stdio frames as bytes - #625
Merged
Merged
Conversation
atesgoral
previously approved these changes
Oct 20, 2026
## Motivation and Context `StdioTransport` reads `$stdin` as UTF-8 and strips each frame before parsing it, in the read loop of `#open` and in the loop of `#send_request` that reads the client's reply. `String#strip` raises for a UTF-8 string holding an invalid byte at either end on every supported Ruby, and anywhere in it from Ruby 3.2 on, and nothing rescued it there: one frame such as `\xff[]`, or a request with an invalid byte in a string value, ended the read loop and the server process, before the parser could answer it. JSON text must be UTF-8 (RFC 8259, section 8.1), and the Python SDK replaces such bytes on its stdio streams instead of stopping. Frames are now stripped as bytes. A frame that is not JSON gets the `-32700` parse error any other unparsable frame gets, and a value holding such a byte reaches the handlers, which serve or refuse it as over HTTP. ## How Has This Been Tested? `test/mcp/server/transports/stdio_transport_test.rb`: a frame starting with an invalid byte, a frame holding one in a value, and a client reply holding one in a value. Against the previous library all three raise from `String#strip` (the value tests from Ruby 3.2 on). ## Breaking Changes None.
koic
force-pushed
the
strip_stdio_frames_as_bytes
branch
from
October 20, 2026 21:56
5ba7060 to
d280b57
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
StdioTransportreads$stdinas UTF-8 and strips each frame before parsing it, in the read loop of#openand in the loop of#send_requestthat reads the client's reply.String#stripraises for a UTF-8 string holding an invalid byte at either end on every supported Ruby, and anywhere in it from Ruby 3.2 on, and nothing rescued it there: one frame such as\xff[], or a request with an invalid byte in a string value, ended the read loop and the server process, before the parser could answer it. JSON text must be UTF-8 (RFC 8259, section 8.1), and the Python SDK replaces such bytes on its stdio streams instead of stopping.Frames are now stripped as bytes. A frame that is not JSON gets the
-32700parse error any other unparsable frame gets, and a value holding such a byte reaches the handlers, which serve or refuse it as over HTTP.How Has This Been Tested?
test/mcp/server/transports/stdio_transport_test.rb: a frame starting with an invalid byte, a frame holding one in a value, and a client reply holding one in a value. Against the previous library all three raise fromString#strip(the value tests from Ruby 3.2 on).Breaking Changes
None.
Types of changes
Checklist