Skip to content

mcp: rejected request IDs receive no JSON-RPC error envelope #1391

Open

Description

@skosovsky

Problem

A syntactically valid, single JSON-RPC request with an ID rejected by the decoder does not receive a JSON-RPC error response:

{"jsonrpc":"2.0","id":true,"method":"ping"}

On upstream main d1a225e:

  • Streamable HTTP returns HTTP 400 with a text/plain body beginning malformed payload, rather than a JSON-RPC error envelope.
  • The IO/stdio transport returns parse error: invalid ID type bool from Read, writes no response, and does not deliver the subsequent valid request in that read call. The connection read loop treats this as a terminal read error.

The same behavior occurs for object and array IDs. These cases reproduce independently of the pending numeric-ID precision fixes.

Expected behavior

For a single request whose ID cannot be accepted, return a JSON-RPC Invalid Request error (-32600) with an explicit id: null. Over HTTP, use HTTP 400 and application/json. Over IO/stdio, write the error and continue reading subsequent valid messages. Do not dispatch the rejected request.

The response ID requirement comes from https://www.jsonrpc.org/specification#response_object. This report concerns structurally invalid IDs, not a new numeric range policy.

Reproduction

HTTP: POST the above body to a StreamableHTTPHandler with Content-Type application/json and Accept application/json, text/event-stream.

IO/stdio: feed the above JSON followed by a newline and {"jsonrpc":"2.0","id":7,"method":"ping"}. The current transport returns an error without writing a JSON-RPC response.

Regression tests reproduce both failures on the unmodified base. Repeating the invalid frame 1000 times before a valid request tests iterative recovery.

Related work and scope

Legacy batch handling, invalid response handling, absent/null request IDs, and malformed JSON recovery are outside this narrowly scoped fix.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions