Repository navigation
A retry answering an upstream's question arrived looking like a first try - #91
Merged
Merged
Conversation
… try MCP's multi-round-trip pattern has a server answer with an input-required result rather than blocking: it returns the questions it needs answered and an opaque requestState, and the exchange completes when the original request is retried with inputResponses filled in and that state echoed back. The specification is emphatic about the echo — a client MUST return the exact value and MUST NOT inspect, parse, modify, or assume anything about it — because the pattern is otherwise stateless and that field carries the whole of the server's context across the round trip. fold rebuilt request params at three sites (tools/call, prompts/get, and the minted ui:// branch of resources/read) and silently dropped both fields. An upstream therefore saw a first attempt every time, asked again, and the client retried — to its ten-attempt ceiling, re-prompting a human on each pass. The other two resources/read branches were always correct, because they forward the params they were handed rather than building new ones; that difference is the whole of the bug. Writing this up exposed a larger thing the fix does not change, now in README "Not implemented" rather than left to be discovered. fold's upstream client runs the SDK's multi-round-trip middleware, which is installed unless explicitly disabled and fold has never disabled it. So in the ordinary case fold does not relay an upstream's question at all: it answers it from the caller's bridged session and issues the retry below the router, and the caller sees one completed call. For a handshake-era caller talking to a modern upstream that is the only thing that can work, and it is era translation rather than proxying. Three consequences follow: a client declaring no elicitation handler has the call failed rather than being asked, resources/read cannot complete such an exchange at all because reads ride the shared root session and it carries no handlers, and a caller that could have answered for itself is never given the chance. Making fold a relay is one line in the client options and a large change to what bridged sessions are for, so it waits on the same decision as roadmap item 13. An invariant is recorded in cachehint.go while it still holds by accident: the specification forbids caching a result produced by an input-required retry, and fold satisfies that only because its one cache holds list results. A response cache on tools/call would break it on the first day. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Second finding from the
/spec-driftsweep. Small fix, plus a larger thing it exposed that is documented rather than changed.The fix
MCP's multi-round-trip pattern: a server needing more input answers with an input-required result carrying its questions and an opaque
requestState; the exchange completes when the original request is retried withinputResponsesfilled in and that state echoed back.The pattern is otherwise stateless, so that field carries the whole of the server's context across the round trip.
fold rebuilt request params at three sites and silently dropped both fields, so an upstream saw a first attempt every time: it asked again, the client retried, and the loop ran to the SDK's ten-attempt ceiling re-prompting a human on each pass.
The shape is the interesting part — the two
resources/readbranches that forwardparamswhole were always correct; only the branch that rebuilds them was broken. Tests pin the minted-ui://branch specifically by asserting the URI the upstream observed, since a genericresources/readtest passes either way.Each of the three sites has a uniquely-identifying failing test under mutation.
What the fix does not change — and why the README now says so
Writing this up exposed that fold does not relay multi-round-trip at all; it absorbs it.
mcp/client.go:79installs the SDK's multi-round-trip middleware unlessMultiRoundTrip.Disabledis set, and fold has never set it. So in the ordinary case fold answers an upstream's question itself — from the caller's bridged session, via elicitation or sampling — and issues the retry below the router. The caller sees one completed call and never sees the question.For a handshake-era caller talking to a modern upstream, that is the only thing that can work: it is era translation rather than proxying. It is also not a relay, and three consequences follow, none yet addressed:
resources/readcannot complete such an exchange at all, because reads ride the shared root session and it carries no handlers — observed surfacing as "Resource not found" after the probe loopTurning fold into a relay is one line in the client options and a large change to what bridged sessions are for, so it waits on the same decision as roadmap item 13 — which was itself designed against the server-initiated mechanism this pattern replaced.
I had this wrong first. My initial README paragraph claimed fold "relays both directions unchanged". It does not, and the test agent caught it. The paragraph now describes what fold actually does, and README "Not implemented" carries the three consequences.
A corollary worth knowing when reading the tests: the end-to-end test (
TestMultiRoundTripCompletesInOneRetry) passes with the bug present, because the retry is generated below the router. The three...ReachesUpstreamtests are the ones holding the fix.An invariant recorded while it still holds by accident
The spec forbids caching a result produced by an input-required retry — such results "depend on inputs that are not part of the cache key". fold satisfies that today only because its one cache holds list results and this pattern applies to
tools/call,prompts/get, andresources/read. A response cache on any of those would break it on day one, so the rule is now written incachehint.gowhere whoever adds one will see it.Verification
go test -race ./...green; lint 0 issues; gofmt / vet cleanInputRequiredResultrequestStateopacity asserted across 9 hostile values × 3 methods — whitespace, JSON-shaped, quotes/backslash/NUL, non-ASCII, decomposed combining marks (proving no NFC normalisation), values shaped like a namespaced tool name and a minted URI, and 16 KiBsanitizeRequestMetaasserted: a request carrying both a forged connection key and a continuation arrives with the key stripped and the continuation intact🤖 Generated with Claude Code