Skip to content

fix(rmcp): surface JSON-RPC error bodies on HTTP 4xx responses - #748

Merged
DaleSeo merged 3 commits into
modelcontextprotocol:mainfrom
kakarot-dev:fix/http-4xx-jsonrpc-error-body
Mar 17, 2026
Merged

fix(rmcp): surface JSON-RPC error bodies on HTTP 4xx responses#748
DaleSeo merged 3 commits into
modelcontextprotocol:mainfrom
kakarot-dev:fix/http-4xx-jsonrpc-error-body

Conversation

@kakarot-dev

Copy link
Copy Markdown
Contributor

When a server returns a 4xx status with Content-Type: application/json, attempt to deserialize the body as a ServerJsonRpcMessage before falling back to UnexpectedServerResponse. This allows JSON-RPC error payloads carried on HTTP error responses to be surfaced as McpError instead of being lost in a transport-level error string.

Fixes#724

Attempt to deserialize HTTP 4xx response bodies as ServerJsonRpcMessage when Content-Type: application/json, surfacing JSON-RPC errors as McpError instead of discarding them as UnexpectedServerResponse.

How Has This Been Tested?

Tested locally with a mock axum server against three scenarios: valid JSON-RPC error body on 400, non-JSON 400, and malformed JSON on 400. All pass.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

I created a test file locally, Test file available if needed

When a server returns a 4xx status with Content-Type: application/json,
attempt to deserialize the body as a ServerJsonRpcMessage before falling
back to UnexpectedServerResponse. This allows JSON-RPC error payloads
carried on HTTP error responses to be surfaced as McpError instead of
being lost in a transport-level error string.
Fixesmodelcontextprotocol#724
When a server returns a 4xx status with Content-Type: application/json,
attempt to deserialize the body as a ServerJsonRpcMessage before falling
back to UnexpectedServerResponse. This allows JSON-RPC error payloads
carried on HTTP error responses to be surfaced as McpError instead of
being lost in a transport-level error string.
Fixesmodelcontextprotocol#724
@kakarot-dev
kakarot-dev requested a review from a team as a code ownerMarch 12, 2026 06:36
@github-actionsgithub-actionsBot added T-core Core library changes T-transport Transport layer changes labels Mar 12, 2026

@DaleSeoDaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this, @kakarot-dev! I have a couple of comments below. It looks like you've done some manual testing, but it would be great if you could add some automated tests to avoid any regressions.

Comment threadcrates/rmcp/src/transport/common/reqwest/streamable_http_client.rs Outdated
Comment threadcrates/rmcp/src/transport/common/reqwest/streamable_http_client.rs Outdated
@github-actionsgithub-actionsBot added T-dependencies Dependencies related changes T-test Testing related changes T-config Configuration file changes labels Mar 13, 2026
@DaleSeo
DaleSeo merged commit 55b478b into modelcontextprotocol:mainMar 17, 2026
16 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Mar 13, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-configConfiguration file changesT-coreCore library changesT-dependenciesDependencies related changesT-testTesting related changesT-transportTransport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@kakarot-dev@DaleSeo