Skip to content

Backport: Propagate body-level errors as synthetic JSON-RPC responses#897

Open
Planview-JamesK wants to merge 1 commit intomodelcontextprotocol:0.17.xfrom
Planview-JamesK:fix/889-body-error-propagation-0.17.x
Open

Backport: Propagate body-level errors as synthetic JSON-RPC responses#897
Planview-JamesK wants to merge 1 commit intomodelcontextprotocol:0.17.xfrom
Planview-JamesK:fix/889-body-error-propagation-0.17.x

Conversation

@Planview-JamesK
Copy link
Copy Markdown

Motivation and Context

Backport of #896 to the 0.17.x branch. 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 sendMessage() for both WebClientStreamableHttpTransport and HttpClientStreamableHttpTransport
  • 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 each for both transports (WebClientStreamableHttpTransportBodyErrorTest and HttpClientStreamableHttpTransportBodyErrorTest):

  • SSE parse error — server returns SSE with malformed JSON
  • 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() for both
WebClientStreamableHttpTransport and HttpClientStreamableHttpTransport
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.

1 participant