Repository navigation
Conversation
## Motivation and Context `MCP::Client::Stdio` answers a server's `ping` inline while it waits for a response, and it already skips a ping whose id is not a JSON-RPC id. A String id holding bytes that are not valid UTF-8 passed that check, and the pong echoing it failed in `JSON.generate` with `JSON::GeneratorError`. The pong's own rescue covers only a pong that cannot be written, so the error escaped and failed the unrelated request whose response the loop was reading. Such a ping is now skipped like one with a malformed id, since a pong could not carry the id back. A number such as `1e400` fails the same way: the parser reads it as an infinite Float, which `JSON.generate` refuses, so a ping carrying one is skipped as well. A String id that is not valid UTF-8 can arrive in a plain ASCII frame too: the json gem's 2.x releases decode a lone surrogate escape into one. ## How Has This Been Tested? `test/mcp/client/stdio_test.rb`: a ping whose id is not valid UTF-8 is not answerable, and one with a valid id still is. Against the previous library the first is answerable. A ping whose id is `1e400`, sent ahead of the awaited response, is not answered and the request completes; against the previous library it raises `JSON::GeneratorError`. ## Breaking Changes None.
atesgoral
approved these changes
Oct 22, 2026
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::Client::Stdioanswers a server'spinginline while it waits for a response, and it already skips a ping whose id is not a JSON-RPC id. A String id holding bytes that are not valid UTF-8 passed that check, and the pong echoing it failed inJSON.generatewithJSON::GeneratorError. The pong's own rescue covers only a pong that cannot be written, so the error escaped and failed the unrelated request whose response the loop was reading.Such a ping is now skipped like one with a malformed id, since a pong could not carry the id back.
A number such as
1e400fails the same way: the parser reads it as an infinite Float, whichJSON.generaterefuses, so a ping carrying one is skipped as well. A String id that is not valid UTF-8 can arrive in a plain ASCII frame too: the json gem's 2.x releases decode a lone surrogate escape into one.How Has This Been Tested?
test/mcp/client/stdio_test.rb: a ping whose id is not valid UTF-8 is not answerable, and one with a valid id still is. Against the previous library the first is answerable. A ping whose id is1e400, sent ahead of the awaited response, is not answered and the request completes; against the previous library it raisesJSON::GeneratorError.Breaking Changes
None.
Types of changes
Checklist