You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The HTTP client returns another request's SSE response and crashes on a server request with id 1e400 #717
MCP::Client::HTTP::SSEStream#feed (lib/mcp/client/http.rb:201) reads the SSE stream a POST is answered with, and differs from MCP::Client::Stdio in two ways:
It takes the first event carrying result or error as the response, whatever its id. A response with another request's id is returned as the answer to the request being sent, and the stream is closed before the real response arrives. Client::Stdio#read_response only returns a response whose id is the awaited one.
It answers a server-to-client request unless its integer id is beyond 128 bits. An id such as 1e400, which the JSON parser reads as Infinity, passes that check, and writing the answer raises JSON::GeneratorError out of send_request, failing the request being sent. Client::Stdio skips a ping whose id it cannot write back (Skip a stdio ping whose id cannot be encoded #628).
To Reproduce
On main (bfd6ed5), with the POST answered by this SSE body:
send_request raises JSON::GeneratorError: Infinity not allowed in JSON. The same happens for elicitation/create and for -1e400.
Expected behavior
A response carrying another request's id is skipped and the request's own response is returned. A server request whose id cannot be written back is dropped unanswered, as one with an oversized integer id already is.
Logs
See above.
Additional context
A server request with a malformed id that can still be written back (an object, null, true) is answered with Method not found, as test_a_ping_with_a_malformed_id_is_answered_with_method_not_found requires; this issue does not change that.
I have a fix with tests and will open a PR for it.
Activity
fix: check the ids of SSE messages in the HTTP client