Repository navigation
Conversation
## Motivation and Context A JSON-RPC id is written back into the response, and `JsonRpcHandler` and the transports accepted an integer id of any size. Writing an integer out in decimal takes time that grows faster than its length: on a Ruby built without GMP, a request whose id has 400,000 digits took 0.6 seconds to answer and one that fills the default 4 MiB body about a minute, most of it spent generating the refusal that echoes the id. Any client can send one, and the id is echoed whether the request is served or refused. `JsonRpcHandler` now answers a request whose integer id is beyond 128 bits with `-32600` Invalid Request and no id, before the method runs, and the Streamable HTTP transport answers such a body 400 before any of its own refusals echoes the id. 128 bits leaves room for any counter and for a UUID carried as a number. On the client, a server-to-client request with such an id is dropped unanswered over HTTP, and a ping with one is not answered over stdio, as for the other ids that cannot be written back. ## How Has This Been Tested? `test/json_rpc_handler_test.rb`, `test/mcp/server/transports/streamable_http_transport_test.rb`, `test/mcp/client/http_test.rb` and `test/mcp/client/stdio_test.rb`. Against the previous library the handler runs the method, the transport echoes the id, and both clients answer the request. The 400,000-digit request above is now refused in 0.07 seconds. ## Breaking Changes A request whose integer id does not fit in 128 bits is refused where it was served. Such an id is beyond what a JSON number can carry between implementations, so no client is expected to send one.
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
A JSON-RPC id is written back into the response, and
JsonRpcHandlerand the transports accepted an integer id of any size. Writing an integer out in decimal takes time that grows faster than its length: on a Ruby built without GMP, a request whose id has 400,000 digits took 0.6 seconds to answer and one that fills the default 4 MiB body about a minute, most of it spent generating the refusal that echoes the id. Any client can send one, and the id is echoed whether the request is served or refused.JsonRpcHandlernow answers a request whose integer id is beyond 128 bits with-32600Invalid Request and no id, before the method runs, and the Streamable HTTP transport answers such a body 400 before any of its own refusals echoes the id. 128 bits leaves room for any counter and for a UUID carried as a number. On the client, a server-to-client request with such an id is dropped unanswered over HTTP, and a ping with one is not answered over stdio, as for the other ids that cannot be written back.How Has This Been Tested?
test/json_rpc_handler_test.rb,test/mcp/server/transports/streamable_http_transport_test.rb,test/mcp/client/http_test.rbandtest/mcp/client/stdio_test.rb. Against the previous library the handler runs the method, the transport echoes the id, and both clients answer the request. The 400,000-digit request above is now refused in 0.07 seconds.Breaking Changes
A request whose integer id does not fit in 128 bits is refused where it was served. Such an id is beyond what a JSON number can carry between implementations, so no client is expected to send one.
Types of changes
Checklist