GeezerVison is showing github.com — Propagate body-level errors as synthetic JSON-RPC responses by Planview-JamesK · Pull Request #896 · modelcontextprotocol/java-sdk
Conversation
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Apr 2, 2026
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
This was referenced Apr 7, 2026
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.