Skip to content

binding-mcp: per-toolkit elicitation for mcp proxy #1810

Description

@jfallows

Summary

Enable the MCP proxy (binding-mcp kind: proxy) to elicit independent authorization
per proxied toolkit
and route the consent flow end-to-end with the connecting MCP client,
using MCP URL-mode elicitation (SEP-1036): the proxy emits/relays a per-toolkit
elicitation/create, correlates and routes the OAuth callback per toolkit, and fires
notifications/tools/list_changed as each toolkit authorizes.

The binding owns only the MCP surface — elicitation emission/relay, the callback
endpoint, and state correlation. The credential scheme that rides on the elicitation
(OAuth: token exchange, dynamic client registration, storage) is not the binding's
concern: it is completed either by the remote MCP server (Track A, OSS relay — Zilla
relays the elicitation and the callback and holds no token) or by an engine Guard
(Track B — a token-exchange-capable guard behind the Guard SPI, e.g. a zilla-plus OAuth
guard). A simple guard works today and a richer OAuth guard drops in later with no
binding-mcp change.

The work hinges on separating two flows (a holdover from when the cache was a
separate binding type): background cache hydration (shared, list-only credential,
tolerant) vs. the live proxy entry point (per-client, auth-eliciting, per-client
execution). See Design §1.

Builds on the examples/mcp.proxy work in #1793.

Scope note: per-client listing filtering by per-tool authorization metadata
(SEP-1488 securitySchemes / operator scope map / annotation fallback, acquirable vs
non-acquirable, cached-baseline ∪ per-identity hybrid serve) is tracked separately in
#1831 — it is a listing-accuracy optimization layered on the signaling this issue
delivers, and is not required for the Track A OSS-relay example.

Motivation

The proxy aggregates several upstream MCP servers behind one endpoint. Authenticated
upstreams (e.g. the local github-mcp-server) challenge with
HTTP 401 + WWW-Authenticate: Bearer resource_metadata="…" (RFC 9728). Today:

  • the bearer-challenge path captures only realm/scope/error — not
    resource_metadata — so a github-style challenge conveys nothing actionable to the
    client (the deferred URL-passthrough item);
  • a 401'd route is silently skipped during aggregation, so the client never learns it
    needs to authorize;
  • the transport-level bearer model is single-credential (one protected resource →
    one token), so it cannot represent N independent per-toolkit credentials at all;
  • cache and live handling share one tolerant path. The per-route auth-failure
    tolerance needed to populate the cache is being imposed on live client requests, so a
    client's tools/list sees the degraded cached aggregate (unauthorized toolkit hidden)
    and is never prompted to authorize.

We want a client to be able to authorize each authenticated toolkit independently and
use the aggregated gateway with no per-upstream token wiring.

Goals

  • Per-toolkit, independent authorization for proxied upstreams, surfaced as per-toolkit
    URL-mode elicitation and routed end-to-end (elicit → callback → reauthorize → list_changed).
  • Cleanly separate cache hydration (shared baseline, list-only credential, tolerant)
    from live request auth (per identity, eliciting, per-client execution).
  • Standards-based: MCP URL-mode elicitation + the URLElicitationRequiredError
    (-32042) array; OAuth callback handled by Zilla, tokens bound to the client identity.
  • Keep all credential semantics behind the Guard SPI; binding-mcp owns only the
    MCP surface (elicitation emission, callback endpoint, state correlation).
  • Default behavior = portable retry model; opt-in single-shot delivery.
  • Never execute with the shared cache credential — every tools/call uses the client's
    own token, so the upstream remains the authoritative enforcer at tools/call.

Background (current building blocks)

  • Guard SPI already anticipates this: reauthorize → NOT_AUTHORIZED | NEEDS_PREAUTHORIZE | sessionId, preauthorize(callback) → authorize URL, async
    reauthorize(credentials=callbackURL) documented "for upstream token exchange after
    an out-of-band consent step", plus credentials/expiringAt/deauthorize.
  • Per-route bootstrap credential exists (binding-mcp: add cache option to mcp · proxy binding #1737, options.authorization on the south
    mcp client) — this issue supersedes/reconciles it into the cache-credential model (§2).
  • URL-elicitation + callback machinery exists (McpElicitCreateChallengeEx{id,url},
    manipulateElicitUrl injecting redirect_uri + state, McpAuthCallbackHandler,
    resolveElicitation) — currently triggered by an upstream elicitation/create,
    and effectively a pre-standard extension under the negotiated protocol 2025-06-18.
  • Streamable-HTTP resumability (McpRequestStream, suspend/resume,
    Last-Event-Id) — the substrate for hold-and-resume.

Design

1. Separate cache hydration from live request auth

Two distinct flows with different identity scope and auth-failure policy; they
must not share one tolerant path.

Cache hydrater Live proxy entry point
Driver background, periodic per client request
Identity one list-only credential the connecting client's identity
Auth failure degrade / skip, populate what succeeds elicit (hold / -32042)
Credential use list only, never invoke execute with the client's own token
Result shared store response to that client
  • The hydrater fans out directly to the route exits to populate the shared store —
    it does not loop back through the proxy entry. (This removes the old
    originId == routedId self-stream detection; the proxy entry then only ever handles
    live client requests.)
  • Correctness constraint: per-client OAuth yields per-identity tokens and tool
    lists. Those must not enter the shared store (cross-user leakage; cf. the draft
    cacheScope: "private" signal). The shared cache is the shareable baseline;
    per-client-authorized content is live / per-identity.
  • Live entry point serves, per identity, the shared baseline + the client's
    per-identity authorized toolkits. Auth surfaces through the operations themselves (§6).

2. Cache (listing) credentials — with.cache, defaulting to options.cache

The credential used to enumerate an upstream's catalog into the shared cache.

  • It is list-only: used by the hydrater to read tools/list etc., never to
    invoke a tool (destructive or not). All invocation uses the client's own token (§4/§7).
    Because it never executes, it can be scoped broadly to enumerate the full superset
    catalog without execution risk (it is still a sensitive secret — guard it).
  • Per-route, on the proxy route's with.cache, with the binding-level
    options.cache.authorization as the default. Precedence: with wins over options.
  • Source split (by capability, via the guard SPI):
    • with = static per-route credential (e.g. a read-only listing PAT) — no guard
      needed.
    • options.authorization.name → guard resolves the credential dynamically
      (token exchange / client-credentials / DCR) — requires a guard that supports it; the
      bundled identity guard does not.
north_mcp_proxy:
  type: mcp
  kind: proxy
  options:
    cache:
      store: cache
      ttl: PT5M
      authorization:           # binding-level default
        name:           #   dynamic, via a token-exchange-capable guard, or
        credentials: <...>     #   static default
  routes:
    - when: [{ toolkit: github, capability: [tools, resources] }]
      exit: south_mcp_client_github
      with:
        cache:
          credentials:    # static (zilla); wins over options

3. Per-client listing accuracy & per-tool scopes — split to #1831

Filtering the aggregated listing per client by per-tool authorization metadata (SEP-1488
securitySchemes / operator scope map / annotation fallback), the acquirable-vs-non-acquirable
distinction, per-identity live listing where metadata is absent, and the cached-baseline ∪
per-identity hybrid serve are tracked in #1831. This issue delivers the underlying
mechanism: the shared cache is the role-neutral baseline, per-identity authorized content is
served live (§1), execution always uses the client's own token (§7), and tools/list fires
list_changed to the authorizing client (§6).

4. Guard does credentials; binding-mcp does the MCP surface

Single guard-agnostic path per route:
reauthorize(inbound-bearer-or-null) → valid → credentials() → stamp; NEEDS_PREAUTHORIZE
→ preauthorize(callback = Zilla connect URL) → authorize URL; on callback feed the
callback URL back into async reauthorize → guard exchanges + stores the token. The
bundled identity guard never returns NEEDS_PREAUTHORIZE; a guard that supports
preauthorize + async reauthorize (token exchange) implements DCR / PKCE / exchange /
refresh / storage behind the same interface — binding-mcp is unchanged either way. Each
route names its own guard (options.authorization.name) →
independent per-toolkit credentials, stored by the guard per (identity, route).

5. Delivery mode = live-exchange property, resolved at the server

Applies to blocking operations on the live entry point (e.g. tools/call);
tools/list is non-blocking (§6).

  • New timeout option on the mcp server binding (default 0).
  • 0 → prompt URLElicitationRequiredError (-32042) → client retries.
  • >0 → hold the request open up to timeout, single-shot via the resumable stream;
    on expiry fall back to -32042.
  • The server resolves the effective timeout (configured value gated by the client's
    negotiated capabilities — elicitation.url + hold/resume tolerance; → 0 if the client
    can't hold) and stamps the effective value on each request's McpXxxBeginEx (default
    0). Per-request carriage matches the per-stream handler model; the proxy honors it to
    choose suspend-and-resume vs tear-down-for-retry.

6. Where auth surfaces (per operation, live entry point)

No synthetic authorize tool — auth surfaces through the operations themselves:

  • tools/list (+ prompts/resources list): non-blocking. Return the authorized
    toolkits' tools immediately, and emit elicitation/create (URL mode) for each
    unauthorized toolkit on the list request's stream. Do not block. On completion fire
    notifications/tools/list_changed (existing McpToolsListChangedFlushEx) → the client
    re-lists → newly-authorized tools appear. This makes tools/list the universal
    discovery + prompt point.
  • tools/call (+ prompts/get, resources/read) to an unauthorized toolkit: blocking.
    timeout==0 → -32042 → retry; timeout>0 → hold + elicitation/create, single-shot.

Each needs-preauth route contributes one ElicitRequestURLParams{mode:"url", url, message, elicitationId} (via preauthorize); the fan-out barriers on all per-route begins
reaching a terminal state. The multi-entry -32042 array is optional (a tools/call
targets one toolkit; tools/list prompts via per-toolkit elicitation/create).

7. Correlation, storage & execution

Each entry carries a server-minted elicitationId; the elicited URL is a Zilla
connect?elicitationId=… URL (anti-phishing), with state binding to identity (not
session id alone, per spec MUST), and provider/client_id/scopes kept server-side in the
guard. Execution tokens are stored per (identity, route) — never in the shared store,
and every tools/call executes with the client's own token, so the upstream remains
the authoritative enforcer
(a client lacking a scope gets 401/403 → no escalation even
if synthesized scopes are wrong). Restrictions the upstream can't model (gateway-level
role policy) must be enforced authoritatively by Zilla at tools/call. Retries
converge and are idempotent (token present → skip).

Protocol version

URL-mode elicitation, the -32042 array, and capabilities.elicitation.url are MCP
2025-11-25
; Zilla negotiates 2025-06-18. SEP-1488 (securitySchemes) and
cacheScope are draft. This work requires a protocol bump + capability negotiation,
and reconciling the existing pre-standard URL-elicitation extension with SEP-1036. Clients
without elicitation.url fall back to degrade.

Proposed phasing

  1. resource_metadata capture + carry on McpBearerResetEx + re-render to client
    (extends binding-mcp: propagate upstream auth challenges to inbound client #1795; testable in isolation, no live OAuth needed).
  2. Split the live entry point from the hydrater (§1); hydrater fans out directly to
    route exits; remove originId == routedId self-stream loopback; shared store = baseline.
  3. Cache (listing) credential model (§2): with.cache static (zilla) over
    options.cache.authorization; list-only usage.
  4. Protocol 2025-11-25 + elicitation.url capability negotiation; reconcile existing
    URL-elicitation with SEP-1036.
  5. Guard-driven NEEDS_PREAUTHORIZE → preauthorize → elicitation → callback → reauthorize
    for a single route (retry / -32042); per-(identity,route) execution storage.
  6. timeout option + per-request McpXxxBeginEx carriage; hold-and-resume path.
  7. Non-blocking tools/list (partial + per-toolkit elicitation/create + list_changed)
    and blocking tools/call.
  8. (moved to binding-mcp: per-client tools/list filtering by per-tool authorization metadata #1831) Per-client listing filter: consume SEP-1488 securitySchemes when
    present; operator-declared mapping + annotation fallback; per-identity live listing where
    absent; cached-baseline ∪ per-identity hybrid serve.
  9. IT coverage of the preauthorize → elicit → callback → reauthorize flow using a test
    guard that exercises NEEDS_PREAUTHORIZE/preauthorize (no live OAuth provider needed).

References

Activity

  1. added theissue type on Jun 2, 2026
  2. self-assigned this
    on Jun 3, 2026
  3. added 2 commits that reference this issue on Jun 4, 2026
  4. jfallows commented on Jun 4, 2026

    @jfallows
    ContributorAuthor

    Broadening scope: support two per-toolkit authorization models behind one binding

    After working through the proxy ↔ upstream authorization flows, there are two distinct models for completing per-toolkit authorization, and the mcp binding should support both so either can be configured with no binding fork. The phasing above already covers the gateway-managed model; this broadens the issue to add the relay model and reconcile the phases. The difference between the models is purely who is the authorization authority and where the token lives — a deployment/config choice, not a code fork.

    Model A — relay (upstream is the authorization authority)

    The upstream MCP server itself originates the URL elicitation; the proxy relays it to the client verbatim and stays out of the OAuth callback path. The upstream binds the authorization to its own session (Mcp-Session-Id). The proxy's responsibilities are narrow:

    1. Pass the elicitation URL through unmodified (do not rewrite state/redirect_uri) so the callback reaches the upstream directly and the upstream can correlate it via its own state.
    2. Maintain a persistent upstream session per (route, connecting session) and replay Mcp-Session-Id + MCP-Protocol-Version on every subsequent request, resuming on reconnect.

    Once the client authorizes (out-of-band, directly with the upstream), the re-issued request on the same session is authorized. No proxy-side token storage; recovery is the standard "auth-required → authorize → retry" pattern. This scales to multiple authenticated upstreams cleanly: each route is isolated (own lifecycle, own Mcp-Session-Id, own elicitation), and because each callback goes direct to its upstream, concurrent elicitations self-correlate with no shared proxy state.

    Model B — gateway-managed (proxy drives OAuth via the Guard SPI)

    Exactly the existing design (§4–§7): preauthorize → elicitation → callback → reauthorize, tokens stored per (identity, route) behind the guard, callback handled by Zilla. Unchanged.

    Both share the MCP surface the binding already owns (elicitation emission/relay, capability negotiation, list_changed, resumable streams). Landing both models' binding-level support together means either example can be built on the merged binding with no further binding work. The initial example demonstrates Model A (relay), building on examples/mcp.proxy (#1793).

    Phase reconciliation (done / still-needed / new)

    Done & still required: 1 (resource_metadata), 2/2e (hydrater split + cache infra), 3 (cache listing credential), 4 (protocol + elicitation.url), 5 (guard preauthorize → reauthorize, incl. inbound-identity reuse — which is also the linchpin that makes the "authorize → re-issue" retry succeed), 6 (timeout + hold-and-resume — see note), 9 (guard-flow ITs).

    Phase 7 splits:

    • 7a (relay): non-blocking tools/list returning authorized tools immediately + relaying each unauthorized upstream's elicitation/create verbatim + relaying the upstream's native list_changed. No state rewriting; proxy out of the callback path.
    • 7b (gateway-managed): the callback-routing machinery — tag the elicitation state per toolkit on the way up, strip + route on the callback back, originate list_changed on reauthorize. Required so a callback routes to the correct toolkit when the list stream is non-blocking (no held-stream correlation available).

    New items (relay model critical path):

    • N1 — origin-conditional URL passthrough: when the elicitation originates from the upstream (not gateway-minted), pass the URL through unmodified; only gateway-minted elicitations get redirect_uri/state rewritten. (manipulateElicitUrl becomes origin-conditional — today it rewrites unconditionally.)
    • N2 — persistent per-route session affinity: keep the per-route upstream lifecycle/session alive for the whole unified client session (lazy-established on first use, reused across request streams, released at session end); capture/replay Mcp-Session-Id + MCP-Protocol-Version; resume on reconnect (Last-Event-Id). Optionally store-backed for durability.
    • N3 — the examples/mcp.proxy example demonstrating elicitation + authorization-guarded list/call via the relay model, scaling to multiple authenticated upstreams.

    Phase 8 (per-client listing filter, §3) unchanged; not required by the initial example — per-identity listing falls out of live per-session listing when no cache credential is configured.

    Note on phase 6

    With the "authorize → re-issue" retry pattern available to both models, the hold-and-resume path (timeout>0) is additive UX (the held request resumes automatically, with no client re-issue round-trip) rather than strictly required. We keep it by design; timeout==0 / -32042 remains the portable default and the hold is the opt-in enhancement. Nothing already implemented needs to be removed.


    Generated by Claude Code

  5. changed the title [-]binding-mcp: per-toolkit `oauth` for `mcp` proxy[/-] [+]binding-mcp: per-toolkit elicitation for `mcp` proxy[/+] on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions