Skip to content

feat(binding-mcp): SEP-1036 url-mode elicitation (passthrough + broker) - #1851

Merged
jfallows merged 12 commits into
developfrom
feat/binding-mcp-url-elicitation
Jun 8, 2026
Merged

jfallows merged 12 commits into
developfrom
feat/binding-mcp-url-elicitation

Conversation

@jfallows

@jfallows jfallows commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Implements SEP-1036 url-mode elicitation in the mcp binding, end to end, with a single north code path shared by passthrough and broker (guard/OAuth) topologies.

What this adds

  • Passthrough url-mode elicitation — the mcp server relays a server-initiated elicitation/create (mode url) to the client over the streaming response or the standalone session GET, relays the client's response back upstream, and relays notifications/elicitation/complete. Covers both session-level (lifecycle GET) and request-coupled (tool call / prompts get / resources read) elicitations.
  • Proxy aggregation — the aggregating mcp proxy relays elicitation across toolkits, prefixing the JSON-RPC correlation id per toolkit so the response and OAuth callback route back to the originating downstream (replacing the prior elicitClients map / context breadcrumb).
  • Broker (guard/OAuth) convergence — the north reacts to elicitation/create identically in broker and passthrough modes. Broker shrinks to its irreducible core: host the OAuth callback and layer routing onto the OAuth state (sessionId.elicitationId.<guard-state>). Discriminated by the create url's redirect_uri being anchored at the server's own callback. The auth-callback URL is plumbed north→south on the lifecycle BEGIN; the guard builds the DCR redirect_uri. Broker now honors decline (the gated tool call fails) instead of hanging.

Notable internals

  • requestId → correlationId rename (elicit-scoped only; generic request machinery untouched).
  • North emits notification-style elicitation/create (no JSON-RPC id) when no correlation id is present (passthrough-remote), else a request with the id (quoted iff non-numeric).
  • One uniform notifications/elicitation/complete{elicitationId}; dropped the broker-only complete/error data-events, the status field, and the McpElicitStatus enum.
  • Supporting fixes folded in: 202 Accepted for notifications/initialized, last-event-id propagation on session-level resume, standalone GET SSE relay, stop upstream keepalive on downstream suspend, bounded session-id minting, and guarding an unknown requestId in notifications/cancelled.

Verification

./mvnw clean verify green for both modules: runtime/binding-mcp 233 ITs and specs/binding-mcp.spec 212 ITs, 0 failures, checkstyle and the coverage gate satisfied. Broker behavior is IT-covered via the engine test guard (no real OAuth guard required); the passthrough path is additionally exercised end-to-end by the examples/mcp.proxy demo (in a follow-up PR).

🤖 Generated with Claude Code

jfallows and others added 12 commits June 7, 2026 19:45
onDecodeNotifyCancelled looked up the request stream by requestId and
called doAppCancel without a null check. A notifications/cancelled for
an unknown or already-completed requestId returned null, dereferenced
it, and threw NPE on the worker thread -> AgentTerminationException,
terminating the EngineWorker (container auto-restarted).

Guard the lookup so an unknown requestId is still acknowledged with
202 Accepted and never terminates the worker. Adds the
notifications.cancelled.unknown scenario (NetworkIT peer-to-peer +
McpServerIT against the engine, which reproduced the AgentTermination
before the fix).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… (WIP)

Defines the conformant url-mode elicitation wire contract so it can be
implemented test-first. Faithful relay: the upstream's original JSON-RPC
request id and elicitationId both flow through unchanged (Zilla invents
neither).

- mcp.idl: McpElicitAction{ACCEPT,DECLINE,CANCEL}, McpElicitResponseFlushEx
  {requestId, action}, +message/+requestId on McpElicitCreateChallengeEx
- McpFunctions: builders/matchers for the above
- tools.call.elicit.completed (net+app, client+server): rewritten to the
  conformant envelope -- elicitation/create as a request WITH id + message,
  client {id,result:{action}} response, notifications/elicitation/complete,
  then the tool result. net+app peer-to-peer pass.

Discriminator for passthrough vs the guard/OAuth broker: an upstream-supplied
request id means passthrough; a Zilla-initiated (guard) elicitation has none
and stays broker. So passthrough is the default and broker is guard-only.

McpServerIT.shouldCallToolElicitCompleted is @ignore'd pending the north
implementation (emit create-with-id, decode the client response into an
elicitResponse FLUSH, emit notifications/elicitation/complete).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…n-stream wiring (WIP)

Request-stream passthrough (north+south+proxy): elicitation/create relayed with upstream JSON-RPC id, result {action} decoded and relayed, conformant notifications/elicitation/complete. Session/GET-stream wiring (lifecycle path) implemented across north/south/proxy. McpFunctions coverage for elicitResponse + elicitCreate requestId/message. NPE crash-guard in McpRequestStream.doAppEnd (null requestId). Conformant tools.call.elicit.completed.proxied scripts; new lifecycle.elicit.completed scenario + ITs (McpServerIT/McpProxyIT/NetworkIT/ApplicationIT). tools.call.elicit.completed.context @ignore'd (broker callback, issue #1810).

All binding-mcp (229, 1 skip) + spec (211) ITs green; coverage met. Example e2e NOT yet working: blocked on north StreamableHTTP SSE response framing (see NORTH_SSE_FRAMING_DESIGN.md) + proxy session GET-listener establishment.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
North answered notifications/initialized with 200 + application/json.
The MCP spec requires a JSON-RPC notification to receive 202 Accepted
with no body, and the StreamableHTTP SDK client opens its standalone
GET SSE stream (the channel for server-initiated requests such as
elicitation/create) only after a 202 to notifications/initialized.
With 200 the client never opens the GET, so server-initiated
elicitation could not be relayed through the gateway.

Emit 202 with no body. Tighten the net client.rpt scripts that send
notifications/initialized to assert the 202 response; previously they
did a bare `read closed`, which hid the wrong status from McpServerIT
while NetworkIT's server.rpt already wrote 202.

Also remove NORTH_SSE_FRAMING_DESIGN.md: its premise (that the
initialize response content-type is the client's capability signal)
was a misdiagnosis superseded by this 202 fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…(server+client)

Two defects prevented server-initiated url-mode elicitation from flowing
end-to-end between the mcp server and mcp client bindings:

1. McpEventStream.onNetClientEnd tore down the standalone GET's reply SSE
   stream (and cleared session.sse) when the client's bodyless GET request
   completed its initial side — which happens immediately, since a GET has no
   body. The standing SSE channel for server-initiated requests was therefore
   destroyed before any elicitation/create could be emitted. Keep the reply
   open on the request-side END; client disconnects are still handled by
   onNetAbort/onNetReset.

2. HttpElicitResponse POSTed the client's {action} response to the upstream
   without a content-length and without honoring flow control, so the body was
   never delivered (the upstream parsed an empty body and elicitInput never
   resolved, hanging the tool call). Declare content-length and send the body
   once the upstream grants sufficient window, as a fire-and-forget request.

Lock the corrected standing-GET semantics in the network IT scripts: the
lifecycle.events.{open,evict,keepalive} and lifecycle.notify.*.list.changed
scenarios now model the GET staying open across the request-side END, and
lifecycle.elicit.completed sends the GET request-side END before the
server-initiated events to regression-test fix (1).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
newSessionId reject-samples a random session id until its hashCode routes
back to the worker that owns the session state (isLocalIndex). The default
attempt budget was workers*2, so each generation returned null with
probability ((N-1)/N)^(2N) ~= e^-2 ~= 13.5%; a null aborts session creation
and hangs the lifecycle.

Raise the default to workers*64 (~e^-64) and extract the three identical
sampling loops in McpClientFactory, McpServerFactory and
McpProxyLifecycleFactory into a shared, unit-testable McpSessionId helper.

McpSessionIdTest emulates EngineWorker.isLocalIndex for an uncapped binding
(mask == all workers): it demonstrates exhaustion at the legacy workers*2 cap
and proves no null at workers*64 across worker counts 1..64.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ends

The south mcp client keepalive pings the remote mcp server every
inactivity.timeout/2 to keep the upstream session alive. When the downstream
client disconnects, north relays a SUSPENDED challenge, but south continued
pinging the remote server until the inactivity timeout reaped the session.

Cancel the keepalive on SUSPENDED (downstream gone) and re-arm it on RESUME
(downstream reconnected), so Zilla stops pinging the remote server once the
remote client has disconnected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a remote client reconnects the standing GET SSE stream with a
Last-Event-Id, the mcp server binding must replay/resume from that event and
propagate it to the remote mcp server. The session-level resume path built the
resume challenge with no id (McpEventStream.onNetBegin -> session.doAppResume
-> resume(b -> {})), and the Last-Event-Id parser only captured a suffix when
the id contained a prefix delimiter, so a plain id like "event-99" was dropped.

Thread the resumed event id through the session resume (mirroring the request
path) and pass the full Last-Event-Id when there is no prefix. End to end this
makes a downstream GET carrying Last-Event-Id produce an upstream GET to the
remote server carrying the same Last-Event-Id.

Wire the lifecycle.suspend.events and lifecycle.events.resume scenarios into
McpServerIT, and complete the lifecycle.events.resume peer scripts to model the
full resume(id) -> resumable -> suspend round-trip so the scenario passes in
McpServerIT, McpClientIT, NetworkIT and ApplicationIT.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…proxy

Make the aggregating mcp proxy hold a standing event stream to each
upstream so server-initiated elicitation/create requests reach the
downstream client, proven end-to-end against the mcp.proxy example.

- onServerChallenge: on a fresh resume (no aggregate event id) establish
  a south lifecycle per route before resuming existing clients, so the
  upstream GET opens when the downstream opens its event stream. In the
  cached case the clients map was empty at resume time, so no standing
  GET opened and elicitation/create had nowhere to flow.
- onClientBegin: issue the standing-GET resume before forwarding queued
  requests, so the upstream receives the GET before the tools/call POST.
  Otherwise elicitInput fires upstream with no event stream and the
  create request is lost on a cold start.
- Stop aggregating the elicitComplete id: it carries the elicitationId
  the client correlates create and complete by, and must pass through
  verbatim like the elicitCreate id.

Covered by McpProxyCacheIT#shouldCompleteLifecycleElicitWhenCached,
which models the deferred-establishment (clients=0) case with a seeded
aggregating cache and asserts the full elicit round-trip.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The elicit correlation id ties together elicit-create, the client's
response, and (for broker mode) the callback — the callback is not part
of a request, so requestId read wrong. Rename the field on the elicit
extension types and the elicit-handling code to correlationId. The
generic JSON-RPC request machinery (session.requests, ordinary request
ids) is unchanged. Behavior-preserving.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add an optional authCallback field to McpLifecycleBeginEx. The north
derives its OAuth callback URL (resolveRedirectURI, as today) and sets
it on the app lifecycle BEGIN; the proxy propagates it onto each south
client's lifecycle BEGIN; the south stores it on the session. Unused
for now — it lets the guard build the authorization URL with the correct
redirect_uri (replacing the north's URL surgery) in a follow-on change.

Additive and behavior-preserving.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…tation

Make the mcp server react to elicitation/create identically in broker
(guard/OAuth) and passthrough modes, shrinking the broker to its
irreducible core: host the OAuth callback and layer routing onto the
OAuth state.

- discriminate broker at the north by the create url's redirect_uri being
  anchored at the server's own callback (replaces the requestId/context
  presence heuristics); reduce manipulateElicitUrl to state-layering only
- south mints the broker elicitationId and correlationId, passes the
  plumbed authCallback to guard.preauthorize, and branches the elicit
  response by mode: passthrough POSTs upstream; broker accept awaits the
  callback, decline/cancel cancels the guard flow and fails the gated
  request
- north emits one notifications/elicitation/complete and relays the
  client answer down uniformly; emit notification-style create when no
  correlationId is present
- proxy prefixes the correlationId per toolkit and routes both the
  response and callback back by that prefix; drop the elicitClients map
  and the context breadcrumb
- drop the status field from elicitComplete and the McpElicitStatus enum

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@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

@jfallows
jfallows merged commit 6c6807a into develop Jun 8, 2026
4 of 5 checks passed
@jfallows jfallows self-assigned this Jun 8, 2026
@jfallows
jfallows deleted the feat/binding-mcp-url-elicitation branch July 1, 2026 23:04
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