Repository navigation
fix(mcp): never re-send a tool call that may have reached the server - #2780
Merged
Merged
Conversation
After a connection drop, withSession reconnected and re-ran every session call, tools/call included, so a tool that ran before the drop could run twice. A tools/call is now re-sent only when none of its HTTP requests could have reached the server: the connection was never obtained, or its own request got a 404 for an unknown session. Otherwise it fails with the existing "request outcome is unknown" error. A recording transport notes, per call, whether its requests reached the server, because the SDK gives every pending call the same session-missing error. resources/read and prompts/get keep reconnect-and-retry. Closes #2734 Co-authored-by: Mecatl <[email protected]>
rdimitrov
approved these changes
Nov 13, 2026
rdimitrov
left a comment
Member
There was a problem hiding this comment.
LGTM. Checked the per-request record against go-sdk v1.8.0: streamableClientConn.Write builds the POST with the call's ctx, so the dispatchKey value reaches dispatchRecordingTransport, and a 404 on that POST is exactly the ErrSessionMissing path in checkResponse. The GetConn-without-GotConn rule, counting 401/3xx/5xx as reached, and the fresh record per attempt all fail towards not re-sending, which is the right direction for side-effecting calls. The tests cover both the replay and the refused-connection retry, and the mutation checks show they'd catch a regression.
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.
Closes #2734.
Problem
withSessionreconnected and re-ran every MCP session call after a connection drop,tools/callincluded. If the drop happened after the server ran the tool, the side effect ran twice. The design treats that as an unknown outcome that is never replayed automatically (credentials-and-lifecycle.md, "Pauses and restart"). This affected direct MCP servers and the MCP broker's protected caller, which goes throughremoteTool.Execute. The broker claims each call before sending it (auth.go), but this retry happened underneath that check.What
For
tools/callonly, a call is re-sent after a drop only when none of its HTTP requests could have reached the server:httptraceGetConnwith noGotConn), or the call made no request at all; orOtherwise the call fails with the existing "request outcome is unknown" error and is not re-sent.
resources/readandprompts/getkeep reconnect-and-retry, and concurrent failing calls still lead to one reconnect.dispatchRecordingTransport(internal/adapter/mcp/reconnect.go) wraps the SDK's HTTP client transport. For a request whose context carries the call's record, it notes whether the server may have received it.withToolCallgives each attempt a fresh record and turns a drop intoerrOutcomeUnknownwhen a request may have reached the server.withSessionnever retries that error.remoteTool.ExecuteandcallTool(theCallMcpWithQuerypath) use it.unavailableMessageextends the existing unknown-outcome path (isAmbiguousTransportFailure) instead of adding a second message.Why record each request instead of trusting
ErrSessionMissing: the SDK fails the whole connection and gives every pending call the same error. A call whose POST was accepted (200, SSE) and whose resume GET then got a 404 receivesErrSessionMissingtoo, although the tool ran. Only the status of the call's own request tells them apart.Tests
New tests in
internal/adapter/mcp/transport_semantics_test.go:remoteTool.Executeand throughcallTool. The tests assert one request, one side effect, no reconnect, and the exact unknown-outcome message.resources/readstill reconnects and retries.Existing reconnect and session-missing tests pass unchanged.
Mutation checks:
ErrSessionMissingas safe to re-send fails the SSE test.Two independent reviews found no path that re-sends a call that may have reached the server, including the SDK's own retries, net/http's internal retry and HTTP/2.
Notes
tools/calldrops that used to recover silently through a re-send now report an unknown outcome, for example a reset or EOF after the request was sent. This is intended.withSession. The test coversresources/readinstead.idempotentHint,readOnlyHint) are untrusted server hints and are not used to allow a re-send.API compatibility
No schema, proto, or wire field changes. The model sees a behaviour change: when an MCP
tools/callloses its connection after the request may have reached the server, the harness no longer reconnects and re-sends it. The tool result is an error readingmcp call failed: MCP server "<name>" unavailable; request outcome is unknown, with acall MCP tool failed:prefix throughCallMcpWithQuery. Such calls previously could succeed silently through a re-send, possibly running a side effect twice, or fail with "unavailable after reconnect". The text reuses the existing unknown-outcome wording, and calls that provably never reached the server keep their retry.