Skip to content

The HTTP client returns another request's SSE response and crashes on a server request with id 1e400 #717

Done

Description

@yorzi

Describe the bug

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:

  1. 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.
  2. 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:

data: {"jsonrpc":"2.0","id":"other_id","result":{"content":[{"type":"text","text":"other"}]}}

data: {"jsonrpc":"2.0","id":"test_id","result":{"content":[]}}

client.send_request(request: { jsonrpc: "2.0", id: "test_id", method: "tools/call", ... }) returns the other_id response.

With this SSE body instead:

data: {"jsonrpc":"2.0","id":1e400,"method":"ping","params":{}}

data: {"jsonrpc":"2.0","id":"test_id","result":{"content":[]}}

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

  1. added
    bug
    on Nov 26, 2026
  2. added a commit that references this issue on Nov 29, 2026
    67dab99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions