Skip to content

Propagate body-level errors as synthetic JSON-RPC responses#896

Open
Planview-JamesK wants to merge 1 commit intomodelcontextprotocol:mainfrom
Planview-JamesK:fix/889-body-error-propagation-main
Open

Propagate body-level errors as synthetic JSON-RPC responses#896
Planview-JamesK wants to merge 1 commit intomodelcontextprotocol:mainfrom
Planview-JamesK:fix/889-body-error-propagation-main

Conversation

@Planview-JamesK
Copy link
Copy Markdown

@Planview-JamesK Planview-JamesK commented Apr 2, 2026

Motivation and Context

Fixes #889. When body-level errors occur during response streaming in sendMessage() (e.g. DataBufferLimitException, JSON parse errors, ReadTimeoutException), the onErrorComplete operator silently drops them. Because sink.success() has already been called when the HTTP response headers arrive, the error has no path to reach the caller. The pending response in McpClientSession.pendingResponses hangs until requestTimeout.

Summary

  • Change onErrorComplete to onErrorResume in HttpClientStreamableHttpTransport.sendMessage()
  • When a body-level error occurs and the message has a request ID, emit a synthetic JSONRPCResponse with INTERNAL_ERROR to the handler so McpClientSession.pendingResponses gets resolved immediately
  • Notifications (no request ID) do not emit synthetic responses

How Has This Been Tested?

Three new tests in HttpClientStreamableHttpTransportBodyErrorTest:

  • SSE parse error — server returns SSE with malformed JSON, error propagates
  • JSON parse error — server returns malformed application/json, synthetic error response emitted to handler with matching request ID
  • Notification — no synthetic response emitted for messages without a request ID

All existing error handling tests continue to pass.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

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

Change onErrorComplete to onErrorResume in sendMessage() so that
body-level errors (DataBufferLimitException, parse errors, etc.)
emit a synthetic JSON-RPC error response to the handler. This
resolves pending responses in McpClientSession immediately instead
of hanging until requestTimeout.

Fixes modelcontextprotocol#889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebClientStreamableHttpTransport: SSE body errors silently dropped, callTool hangs until timeout

1 participant