Skip to content

reqwest streamable HTTP client drops JSON-RPC error bodies on HTTP 4xx into TransportSend #724

Closed

Description

@adam-r-kowalski

Describe the bug
A POST over Streamable HTTP that returns HTTP 4xx with Content-Type: application/json and a valid JSON-RPC error body is currently surfaced by the reqwest client as a transport error (UnexpectedServerResponse -> ServiceError::TransportSend) instead of a parsed JSON-RPC error (ServiceError::McpError).

This was reported in PR comment thread:
#709 (comment)

To Reproduce
Steps to reproduce the behavior:

  1. Use the current main behavior in crates/rmcp/src/transport/common/reqwest/streamable_http_client.rs where non-2xx is handled before JSON parsing.
  2. Send a request to a server that responds with:
    • status: 400 Bad Request
    • header: Content-Type: application/json
    • body: {"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Unknown prompt: example_prompt"}}
  3. Observe the response is returned as transport error instead of JSON-RPC error object.

Regression test I added for this behavior:

  • crates/rmcp/tests/test_streamable_http_http_error_jsonrpc.rs

Command used:

cargo test -p rmcp --test test_streamable_http_http_error_jsonrpc --features "client server transport-streamable-http-client-reqwest transport-streamable-http-server"

Expected behavior
If response body is valid JSON-RPC and Content-Type is application/json, it should be parsed and surfaced as JSON-RPC message (so request callers receive ServiceError::McpError for error responses), even when HTTP status is 4xx.

This appears consistent with Streamable HTTP spec language that for non-accepted inputs, server may return HTTP error status and response body may be JSON-RPC error response:

Logs
Observed error shape from failing regression expectation before fix:

Err(UnexpectedServerResponse("HTTP 400 Bad Request: {\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-32602,\"message\":\"Unknown prompt: example_prompt\"}}"))

Additional context

Activity

  1. howardjohn commented on Mar 4, 2026

    @howardjohn
    Contributor

    Thanks @adam-r-kowalski !

    cc @alexhancock from the original PR

  2. DaleSeo commented on Mar 7, 2026

    @DaleSeo
    Member

    Closing this as resolved.

  3. DaleSeo commented on Mar 7, 2026

    @DaleSeo
    Member

    My bad, reopening.

  4. reopened this on Mar 7, 2026
  5. kakarot-dev commented on Mar 11, 2026

    @kakarot-dev
    Contributor

    I have a fix for this, happy to open a PR

  6. DaleSeo commented on Mar 11, 2026

    @DaleSeo
    Member

    Hey @kakarot-dev, please go ahead and send a PR. We'd be happy to review :)

  7. added 2 commits that reference this issue on Mar 12, 2026
    7e03278
    c09c6a3
  8. added a commit that references this issue on Mar 17, 2026
    55b478b
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

    bugSomething is not working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions