Backport: Propagate body-level errors as synthetic JSON-RPC responses#897
Open
Planview-JamesK wants to merge 1 commit intomodelcontextprotocol:0.17.xfrom
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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), theonErrorCompleteoperator silently drops them. Becausesink.success()has already been called when the HTTP response headers arrive, the error has no path to reach the caller. The pending response inMcpClientSession.pendingResponseshangs untilrequestTimeout.Summary
onErrorCompletetoonErrorResumeinsendMessage()for bothWebClientStreamableHttpTransportandHttpClientStreamableHttpTransportJSONRPCResponsewithINTERNAL_ERRORto the handler soMcpClientSession.pendingResponsesgets resolved immediatelyHow Has This Been Tested?
Three new tests each for both transports (
WebClientStreamableHttpTransportBodyErrorTestandHttpClientStreamableHttpTransportBodyErrorTest):application/json, synthetic error response emitted to handler with matching request IDAll existing error handling tests continue to pass.
Types of changes
Checklist