Skip to content

A routing header the caller sent stopped at the gateway - #93

Merged
blakebauman merged 1 commit into
mainfrom
fix/forward-mcp-param-headers
Aug 26, 2026
Merged

blakebauman merged 1 commit into
mainfrom
fix/forward-mcp-param-headers

Conversation

@blakebauman

Copy link
Copy Markdown
Member

The last open code finding from the /spec-drift sweep. With this, every finding from it is landed, documented, or in flight.

The gap

Intermediate servers that do not recognize an Mcp-Param-{Name} header MUST forward it and otherwise ignore it, as required by the HTTP Semantics RFC.

Mcp-Param-{Name} is how a client mirrors selected tool arguments into HTTP headers so an intermediary can dispatch without parsing the body. fold is that intermediary and dropped them — its upstream leg is a fresh SDK client session whose headers the SDK generates. Measured against a real upstream before touching anything: it saw none of the caller's headers.

Both halves of the sentence

fold forwards them and ignores them: it does not read the values, does not route on them, and lets nothing they contain influence a decision. The body stays the only thing fold parses, which is what keeps these a hint rather than a second, forgeable control surface.

The relay is the narrowest thing that satisfies the rule. fold forwards no other client header — a standing design decision, and the reason a caller cannot smuggle a credential to an upstream — so I did not want a spec-mandated relay to quietly become a general one. Verified in the same test:

Mcp-Param-Tenant = "acme"          ← crosses
Authorization = ""  Cookie = ""  X-Custom = ""   ← do not

The narrowness is asserted in six places. Widening the relay fails all of them.

Precedence: a value the SDK generated always wins over the caller's. Not because it is fresher — because the spec requires the header to agree with the body, and only a value derived from the body fold is about to send is guaranteed to. Caller-wins would let a caller manufacture a mismatch that a conforming upstream then rejects as its own error.

Two consequences documented rather than smoothed over

Both came out of testing, and the first makes a claim in my first draft wrong:

"fold ignores them" is true of fold, not of the deployment. An upstream's transport validates a param header against the body only once it has negotiated 2026-07-28 — and fold's default upstream protocol deliberately sits below that, so the sessionful handshake can carry server-initiated traffic. So on a default deployment nothing validates these: a balancer in front of an upstream dispatches on a caller-supplied value fold's policy engine never saw and that need not agree with the body fold authorized. README now says it plainly: route on these and you must check them yourself.

They ride the request context, so every upstream request under one carries them — including the bridged session's own initialize, issued lazily inside the first named invocation. Measured:

upstream POSTs carrying Mcp-Param-Tenant: [initialize notifications/initialized tools/call]

Harmless as the spec is written, but a value scoped to one call can reach a router deciding where a whole session lives.

Verification

  • go test -race ./... green; lint 0 issues; gofmt / vet clean; conformance 40/40
  • bench 0.189 ms added p50 (gate 5 ms); withParamHeaders asserted allocation-free on the no-header path via testing.AllocsPerRun, which is the common case
  • Pre-fix check: removing the two wiring lines fails every forward test, and the SEP-2243 round trip fails with the exact conformance error — header mismatch: missing Mcp-Param-Tenant header for parameter "tenant"
  • End-to-end SEP-2243 test runs the upstream leg at protocol: "auto" so the SDK server actually enforces header/body agreement
  • A direct-to-upstream control leg runs first and asserts the probe sees all six headers unfiltered, so the gateway leg's absences are attributable to fold rather than to a blind fixture
  • Fuzz target over the relay (1.69M execs): nothing outside the namespace crosses however spelled, and a preset value is never replaced

🤖 Generated with Claude Code

MCP lets a client mirror selected tool arguments into Mcp-Param-{Name}
headers so an intermediary can dispatch without parsing the JSON-RPC
body, and the transport addresses intermediaries by name: one that does
not recognize such a header "MUST forward it and otherwise ignore it".
fold is that intermediary and dropped them. Its upstream leg is a fresh
SDK client session whose headers the SDK generates, so nothing the
caller set survived the hop — measured against a real upstream, which
saw none of them.

Both halves of that sentence are implemented. fold forwards them and
ignores them: it does not read the values, does not route on them, and
lets nothing they contain influence a decision, so the body stays the
only thing fold parses and the headers cannot become a second,
forgeable control surface.

The relay is the narrowest thing that satisfies the rule. fold forwards
no other client header — a standing decision, and the reason a caller
cannot smuggle a credential or an identity assertion to an upstream
through one — and this is the single namespace a specification requires
be passed through. It never overwrites a value the SDK generated, which
is not about freshness: the specification requires the header to agree
with the body, and only a value derived from the body fold is about to
send is guaranteed to, so caller-wins would let a caller manufacture a
mismatch a conforming upstream then rejects. And it sits inside the same
host bound as credential attachment, so nothing caller-supplied rides a
request to a host the upstream did not configure.

Two consequences are documented rather than smoothed over, because
neither is visible from the code and one of them makes a claim in the
first draft of this change wrong.

"fold ignores them" is true of fold and not of the deployment. An
upstream's own transport validates a param header against the body only
once it has negotiated 2026-07-28, and fold's default upstream protocol
sits below that so the sessionful handshake can carry server-initiated
traffic. So on a default deployment nothing validates these at all, and
a balancer in front of an upstream would dispatch on a caller-supplied
value fold's policy engine never saw and that need not agree with the
body fold authorized. README says so beside the feature: route on these
and you must check them yourself.

And they ride the request context, so every upstream request made under
one carries them — including the bridged session's own initialize, which
is issued lazily inside the first named invocation. A value scoped to
one call can therefore reach a router deciding where a whole session
lives.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 78eb75d into main Aug 26, 2026
8 checks passed
@blakebauman
blakebauman deleted the fix/forward-mcp-param-headers branch August 26, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant