Skip to content

feat(binding-mcp): proxy hydration/forwarding fixes + per-upstream bootstrap credential - #1818

Merged
jfallows merged 7 commits into
developfrom
feature/1817-binding-mcp-proxy-fixes
Jun 2, 2026
Merged

jfallows merged 7 commits into
developfrom
feature/1817-binding-mcp-proxy-fixes

Conversation

@jfallows

@jfallows jfallows commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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.proxy
branch (#1793), after cache refresh (#1814) and the single session-id contract (#1816).

Fixes #1817.

Changes

  • fix: frame client HTTP request bodies with Content-Length.
  • feat: frame streamed request bodies with Content-Length — the server stamps a
    guesstimate contentLength on McpBeginEx; the client declares a south Content-Length
    and whitespace-pads (no buffering / chunked) for streamed tools/call / prompts/get /
    resources/read.
  • fix: grant the proxy reply window when the request reply begins (north tools/list
    reply-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 a
    never-established route (sessionId == null) and isolate its per-route lifecycle failure
    from 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 — RedirectFW carried sessionId.hashCode()
    sign-extended; binding-http folds it via Long.hashCode, so a negative hash routed the
    cross-worker redirect to the wrong worker → re-redirect → HTTP 500 for ~half of sessions
    under multiple workers. Widen with Integer.toUnsignedLong so 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) are
excluded and remain on the example branch. After this, only examples/mcp.proxy remains
on #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

jfallows and others added 7 commits June 2, 2026 15:51
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)

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

binding-mcp: proxy hydration/forwarding fixes + per-upstream bootstrap credential

1 participant