Repository navigation
feat(binding-mcp): proxy hydration/forwarding fixes + per-upstream bootstrap credential - #1818
Merged
Merged
Conversation
The mcp client sent its HTTP requests with neither content-length nor transfer-encoding, so binding-http emitted the body unframed and upstream MCP servers could not read it — initialize was rejected with 400 "No valid session ID provided", which then cascaded (the client fell back to its locally minted id on every subsequent request). The mcp.proxy example stalled on initialize as a result. Set content-length on the requests whose body is fully built before sending: initialize, notifications/initialized, keepalive ping, and the tools/prompts/resources list requests. Streamed requests that forward application data (tools/call, prompts/get, resources/read) still need chunked framing and are left for follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit f858627)
Streamed MCP requests (tools/call, prompts/get, resources/read) forward the params object verbatim through server -> proxy -> client, so the client could not previously set a Content-Length on the upstream HTTP request and the body went out unframed (rejected by spec-compliant MCP servers). The mcp server now requires content-length on the inbound HTTP begin-ex for these three kinds and stamps a guesstimate params length (contentLength - paramsStartOffset - 1) on the McpBeginEx. The proxy relays it; the client declares the south Content-Length (envelope prefix + guesstimate + closing brace), counts the params bytes it forwards, and pads the close with trailing whitespace to reconcile the declared length with the bytes actually sent. For a canonical minified body the guesstimate equals the real params length, so padding is zero; it is provably never negative. No buffering and no chunked transfer-encoding. Adds int32 contentLength to the three streamed begin-ex types, McpFunctions builder/matcher support, the content-length/contentLength assertions across the streamed-kind spec scripts, and a reject scenario for a streamed POST that omits content-length. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit bb30e2d)
A cache-served list reply (and any proxied reply) could hang forever: the mcp server's HTTP response window arrives from binding-http proactively, before the per-request McpRequestStream exists, so onNetWindow skips flushAppWindow (stream == null). After the request stream is created no further onNetWindow arrives, so the downstream proxy is never granted a reply window and can never emit the response — the north tools/list blocks even though the cache is populated. Grant the reply window in McpRequestStream.onAppBegin, when the reply begins and the net window is already available; onNetWindow -> flushAppWindow still covers the reverse ordering. Bounded by encodeMax (the existing encodeSlot capacity), so no over-grant. Verified end-to-end against @modelcontextprotocol/server-everything: north tools/list returns in ~12ms (previously a multi-second hang) and tools/call completes. Full binding-mcp verify remains green (186 ITs + unit + jacoco). The race depends on binding-http's proactive response-window grant, which the k3po-scripted ITs do not reproduce, so it is covered by e2e + no-regression rather than a dedicated IT. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit f067e06)
…oxy body
The aggregating proxy advertises tools with a toolkit prefix (e.g.
everything__echo) and strips that prefix onto the begin-ex identifier for
routing, but forwarded the request body verbatim — so the upstream received
the prefixed name and rejected it ("Tool ... not found"). The body tool name
must match the (stripped) begin-ex name.
The proxy now strips the prefix from the name/uri value in the first forwarded
content frame (route.prefix gives the prefix it already strips for routing) and
reduces the propagated contentLength by the prefix length, so the south
Content-Length is exact with no padding. Existing toolkit fixtures are corrected
so the body name equals the begin-ex name (they previously baked in the
mismatch).
Verified end-to-end against @modelcontextprotocol/server-everything: an agent
call to everything__echo now reaches the upstream as echo and returns its
result. Full binding-mcp verify green (186 ITs + unit + jacoco) and spec verify
green (174 ITs + unit).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
(cherry picked from commit b3a939e)
…ydration When an aggregating mcp proxy fans out to multiple toolkits, one south route that never establishes a session during cache hydration (e.g. a 401 from an unauthenticated upstream) tore down the shared hydrater lifecycle, aborting the healthy routes' in-flight hydration and degrading the whole per-kind cache to empty (and earlier, looping). Now such a route is skipped and the healthy routes aggregate normally. - McpListServer skips a route whose lifecycle settles without a session (onClientSkip advances to the next route) instead of aborting the aggregation. - A per-route lifecycle reset/abort during hydration (server.hydrating() && sessionId == null) no longer tears down the shared hydrater lifecycle; its pending list requests settle and skip. An established session that later aborts still reconnects, preserving recovery. Adds an IT (cache.hydrate.toolkit.multi.skip.unauthorized) where the first route rejects with a bearer challenge and the second route still hydrates, and healthchecks + depends_on service_healthy in the mcp.proxy example so zilla waits for its upstreams. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…t binding
An aggregating mcp proxy fans out to upstream toolkits, some of which require a
bearer token even to list tools (e.g. GitHub Copilot). The background cache
hydrater has no inbound client token, so such a route could never hydrate and
its tools never appeared.
Add options.authorization.credentials on the mcp client binding: when an inbound
stream carries no client token, the binding falls back to this configured
service credential. This serves both cache hydration and token-less live calls,
while an inbound client token still wins. The guard name is now optional so a
guard-less literal bootstrap is allowed; an empty resolved value (e.g. unset
${{env.X}}) is treated as absent so the route is gracefully skipped.
The bearer was previously injected only on tools/call; hydration drives the
initialize and list streams, so resolve the credential centrally in the base
McpStream.proceedWithRequest and inject it via a shared McpHttpStream helper on
every request encoder (initialize, tools/prompts/resources list, prompts/get,
resources/read, notify, keepalive, events). tools/call gates the per-user
elicit/preauthorize challenge on the absence of a bootstrap credential.
Wires the mcp.proxy example github route to ${{env.GITHUB_TOKEN}} (raw token)
and documents it; without the token the github route is gracefully skipped and
the everything and time toolkits still aggregate.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ned worker A misaligned follow-up is steered to its session's worker via RedirectFW, whose affinity binding-http folds through supplyInitialId(routedId, Long.hashCode(affinity)). The server carried sessionId.hashCode() sign-extended into the long affinity, so a negative hash folded to a different worker than the session's alignment, causing a re-redirect and an HTTP 500 for roughly half of all sessions under multiple workers. Widen the hash with Integer.toUnsignedLong so the fold round-trips to the alignment. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 6712736)
This was referenced Jun 2, 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.
Description
The remaining MCP proxy hydration/forwarding fixes plus the per-upstream bootstrap
credential — the third and final binding-mcp extraction from the
examples/mcp.proxybranch (#1793), after cache refresh (#1814) and the single session-id contract (#1816).
Fixes #1817.
Changes
fix: frame client HTTP request bodies withContent-Length.feat: frame streamed request bodies withContent-Length— the server stamps aguesstimate
contentLengthonMcpBeginEx; the client declares a southContent-Lengthand whitespace-pads (no buffering / chunked) for streamed
tools/call/prompts/get/resources/read.fix: grant the proxy reply window when the request reply begins (northtools/listreply-window race).
fix: strip the toolkit prefix from the forwarded tool name in the proxy request body.fix: degrade gracefully when a south route fails cache hydration — skip anever-established route (
sessionId == null) and isolate its per-route lifecycle failurefrom the shared hydrater, so healthy routes still aggregate.
feat: per-upstream bootstrap credential on the mcp client binding(
options.authorization.credentials) — used when there's no inbound client token.fix: widen the redirect hash unsigned —RedirectFWcarriedsessionId.hashCode()sign-extended; binding-http folds it via
Long.hashCode, so a negative hash routed thecross-worker redirect to the wrong worker → re-redirect → HTTP 500 for ~half of sessions
under multiple workers. Widen with
Integer.toUnsignedLongso the fold round-trips.Notes
General binding-mcp behavior, independent of the example. The example-config edits that
accompanied two of these commits (
degrade gracefully,bootstrap credential) areexcluded and remain on the example branch. After this, only
examples/mcp.proxyremainson #1793.
Testing
./mvnw verify -pl specs/binding-mcp.spec,runtime/binding-mcp— binding-mcp ITs(server/client/proxy/lifecycle/cache) + spec ITs green, against develop's engine
(post #1816).
🤖 Generated with Claude Code