mcp: don't mutate caller params on multi-round-trip retries - #1145
Open
yhxlele wants to merge 1 commit into
Open
mcp: don't mutate caller params on multi-round-trip retries#1145yhxlele wants to merge 1 commit into
yhxlele wants to merge 1 commit into
Conversation
yhxlele
added a commit
to akuity/protomcp
that referenced
this pull request
Aug 5, 2026
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.
Fixes #1144.
clientMultiRoundTripMiddlewarecallssetMultiRoundTripRetryParams(req, ...), which writesInputResponsesandRequestStatethrough the caller's params pointer and never clears them. A*CallToolParams(orGetPromptParams/ReadResourceParams) struct reused across calls then carries the first call's answers into the next call: a server gating onlen(req.Params.InputResponses) == 0— the idiom in this repo's own tests and examples — treats the fresh call as already answered, so the client'sElicitationHandlernever fires and an elicitation-gated (e.g. destructive) tool runs without confirmation.This change makes the retry loop carry the fulfilled responses and echoed state on a shallow copy of the params (
multiRoundTripRetryRequest) instead of mutating the original request. Caller-owned params are now left untouched byCallTool,GetPrompt, andReadResource. The server-side shim (serverMultiRoundTripMiddleware) is unchanged: the params it mutates are SDK-owned, decoded from the wire.Tests:
TestMultiRoundTrip_AutoRetryDoesNotMutateCallerParams(CallTool: params unchanged after the call, and reusing the same struct fulfills the input requests again instead of silently replaying the first call's answers — it failed withelicitations after reuse = 1, want 2before the fix), plus GetPrompt/ReadResource analogues asserting params are left clean. All three fail on main and pass with this change;go test ./...andgo vet ./...are clean.Note on observable behavior: callers can no longer read the fulfilled responses off their own params struct after a call returns. That side effect was undocumented, and relying on it is exactly what makes the replay hazard above possible.