Skip to content

feat(binding-mcp): single session-id contract, negotiated protocol-version, partial-success hydration - #1816

Merged
jfallows merged 2 commits into
developfrom
feature/1815-binding-mcp-session-id-contract
Jun 2, 2026
Merged

jfallows merged 2 commits into
developfrom
feature/1815-binding-mcp-session-id-contract

Conversation

@jfallows

@jfallows jfallows commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

The single session-id contract across the mcp server/proxy/client, with negotiated
MCP-Protocol-Version
and per-toolkit partial-success hydration. Fixes the mcp.proxy
400 "No valid session ID" retry-storm (the cache hydrater originated a local session id
the remote never issued).

Extracted from the examples/mcp.proxy branch (#1793); second of three sequential
binding-mcp extractions (cache refresh #1813 → this → proxy fixes + bootstrap credential).
Fixes #1815.

Commits

  1. feat(engine,binding-mcp): isLocalIndex worker affinity + worker-aligned local session-id generation — a prerequisite split from the example commit "prevent stall on
    local sessionId generation" (example edits excluded). Adds the engine SPI
    EngineContext.isLocalIndex + LongIntPredicate util (EngineWorker impl;
    EchoWorker/TlsWorker test EngineContext implementers updated per the engine SPI
    convention), and mints worker-aligned session ids in McpServerFactory.
  2. feat(binding-mcp): single session-id contract, negotiated protocol-version, partial-success hydration — see below.

What commit 2 does

Single session-id contract (WS1): lifecycle (initialize) requests carry no sessionId;
the reply carries the minted id; non-lifecycle requests carry it (one id per stream). The
proxy mints a worker-aligned unified id and is the sole minter/mapper, hash-routing each
south request by its id; the server maps S↔U and still returns S on the HTTP
mcp-session-id header; the client adopts the remote-minted X for the outbound HTTP
header; the cache hydrater sends no id and adopts the proxy-minted one. New engine util
LongIntToLongFunction for hash-routed supplyInitialId.

Negotiated MCP-Protocol-Version (WS3): default 2025-06-18; capture
result.protocolVersion from the initialize response and send the negotiated version on
subsequent request headers.

Per-toolkit partial success (WS2): hydrate.attempts.max bounds per-kind retries; on
exhaustion the kind is marked degraded (settled = populated || degraded) and serves an
empty list envelope instead of aborting.

Engine SPI note

Adds one method to EngineContext (isLocalIndex), with all in-tree implementers
updated
(EngineWorker, plus the EchoWorker/TlsWorker test implementers).

Testing

./mvnw verify -pl specs/binding-mcp.spec,runtime/binding-mcp — server/client/proxy/
proxy-lifecycle/proxy-cache ITs, McpConfigurationTest, and spec application/network/cache
ITs green, incl. new lifecycle.initialize.version (negotiation) and
cache.serve.tools.list.degraded (partial-success) scenarios. Engine + EchoWorker/
TlsWorker compile with the new SPI; CI runs the full engine suite.

🤖 Generated with Claude Code

jfallows and others added 2 commits June 2, 2026 15:42
…ed local session-id generation

Split from the mcp.proxy commit "prevent stall on local sessionId generation" (71191fd);
example edits excluded. Adds EngineContext.isLocalIndex + LongIntPredicate util (EngineWorker
impl; EchoWorker/TlsWorker test EngineContext implementers updated) and mints worker-aligned
session ids in McpServerFactory. Prerequisite for the single session-id contract.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rsion, partial-success hydration

Fixes the mcp.proxy 400 "No valid session ID" retry-storm where the cache
hydrater originated a locally-generated session id on its lifecycle request
and the proxy passed it through, so south requests carried an id the remote
never issued.

Single session-id contract (WS1):
- A lifecycle (initialize) request carries NO sessionId; the reply carries the
  minted id; non-lifecycle requests carry it. One id per stream everywhere; the
  client's responseSessionId dual is removed in favor of an app-id (Xc) vs
  transport-id (X) split (transportSessionId()).
- Proxy mints a worker-aligned unified id and is the sole minter/mapper; the
  lifecycle owns its deferred per-route request streams (McpRouteRequest
  register/settle) and walks them once the route lifecycle settles, hash-routing
  each south request by its session id.
- Server learns U from the app lifecycle reply, maps S<->U, hash-routes request
  streams by U, and still returns S on the HTTP mcp-session-id header.
- Client mints aligned Xc inbound, returns it on the app reply, adopts the
  remote-minted X from the initialize response and uses X only as the outbound
  HTTP header.
- Cache hydrater sends its lifecycle with no id and adopts the proxy-minted id
  from the reply.
- New engine util LongIntToLongFunction for hash-routed supplyInitialId.

Negotiated MCP-Protocol-Version (WS3):
- Default 2025-06-18 (was non-standard 2025-11-25); capture result.protocolVersion
  from the initialize response and send the negotiated version on subsequent
  request headers.

Per-toolkit partial success (WS2):
- New hydrate.attempts.max bounds per-kind hydrate retries; on exhaustion the
  kind is marked degraded so cache readiness no longer requires every kind
  populated (settled = populated or degraded); a degraded kind serves an empty
  list envelope instead of aborting.

Tests: binding-mcp engine ITs (server/client/proxy/proxy-lifecycle/proxy-cache),
McpConfigurationTest, and spec application/network/cache ITs all pass; new
lifecycle.initialize.version negotiation scenario and cache.serve.tools.list.degraded
partial-success scenario added.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
(cherry picked from commit 8e93670)

@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: single session-id contract, negotiated protocol-version, partial-success hydration

1 participant