Skip to content

feat: carry a client's rendering declaration to the upstream - #75

Merged
blakebauman merged 1 commit into
mainfrom
feat/mcp-apps-capability-parity
Aug 15, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/mcp-apps-capability-parity

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Second and final half of MCP Apps support; #74 was the routing half.

The defect

MCP Apps (SEP-1865) is negotiated by the client: a server checks capabilities.extensions["io.modelcontextprotocol/ui"] before registering UI-enabled tools and serves a text-only fallback to anyone who did not declare it. There is no reciprocal server capability, so an upstream that hears nothing assumes no — and fold declared nothing at all, on every session, for every caller.

Measured against a real gated upstream, one hop after the host declared app support to fold:

[gated] initialize from {"name":"fold-gateway",...} extensions=null → TEXT-ONLY fallback

The host asked for apps, the upstream offered them, and the gateway in between lost the question. It is the invisibility rule broken in the direction nobody reports: fold just looks like a server whose upstreams have no apps.

The fix: proxy the declaration, don't configure it

Session Change
bridged (per client, carries named invocations) declares what its own client declared
root (shared, carries lists/reads/subscriptions) keyed by a normalized capability profile, along with its list-cache and decode-memo entries

A shared session cannot hold two answers, so the profile partitions it — one session per upstream in a federation whose clients are alike (exactly today's cost), two in a mixed one, and neither client ever served the other's list.

No config field, not even an opt-out. An operator who does not want an upstream's app variants in the federation is expressing a policy, and fold has a policy engine; a handshake setting that works by misreporting the client would be a control with the wrong name.

The profile is fold's vocabulary, not the client's map. It is computed from the extension identifiers fold implements — keying on client input would let one caller declaring a thousand invented extension ids mint a thousand root sessions and cache entries per upstream. The profile also qualifies the ListCache key, which reaches Redis, where a profile-blind key would let one instance's app-aware list be served to another instance's plain client.

Two notes from implementation

  • list_changed invalidates every profile's entry, not just the one whose session heard it. The notification arrives on one connection and says nothing about the others, but it is the same upstream that changed for all of them — a stale entry the notification did not name is the bug list_changed exists to prevent.
  • The public-view memos became per-profile maps. A single slot stays correct (it validates by slice identity) but two alternating clients would rebuild it on every request.

The design record expected the root-session change to be the expensive part — endpoint pinning, reload drain, subscription ownership. It was not: u.roots has been a keyed map since caller-derived credentials needed one session per principal, so this was two lines on rootKey, and reconnect/resubscribe/drain already worked against the map. The feared duplicate resources/updated fan-out cannot arise either, since the gateway ref-counts one upstream subscription per URI across all clients.

Verification

Six new tests in gateway/uicapability_test.go, against a real SDK upstream that gates registration on the declared capability:

  • an app-aware client gets the app-enabled tool, and the upstream confirms it saw the declaration;
  • a plain client gets the fallback, and the upstream never sees a UI declaration in a federation with no app-aware client;
  • both clients interleave tools/list three times, neither served the other's;
  • a tools/call carries the declaration on the bridged session;
  • the profile ignores invented extension ids and future mime types;
  • cache keys do not collide across profiles.

Full suite green under -race, golangci-lint clean, added p50 178.9µs (gate: < 5ms), and conformance 40/40 — run locally because this touches the handshake.

Scope

No config field, no new error code, no new audit method, no schema lockstep. Docs move with it: README gains the negotiation paragraph and its "Not implemented" bullet narrows to the two remaining gaps, CLAUDE.md's "two kinds of upstream session" now describes the keyed root map, roadmap item 15 is marked shipped.

Still open, and not fold's to close: an app that hardcodes a tool name cannot call it once federation has namespaced it, and the host's cross-server rule for app-only tools has no meaning behind a gateway where every upstream shares one connection. Both need answers in the extension's specification; issues to follow.

🤖 Generated with Claude Code

MCP Apps is negotiated by the client: a server is advised to check
capabilities.extensions["io.modelcontextprotocol/ui"] before registering
UI-enabled tools, and to serve a text-only fallback to anyone who did not
declare it. There is no reciprocal server capability, so an upstream that
hears nothing assumes no — and fold declared nothing at all, on every session,
for every caller. A host that told fold it could render apps was served the
fallback: the invisibility rule broken in the direction nobody reports, since
the gateway simply looks like a server whose upstreams have no apps.

Measured against a real gated upstream before this change: the upstream
logged `extensions=null` from fold-gateway and registered its text-only
tool, one hop after the host had declared the extension to fold.

fold now carries the declaration rather than configuring it — there is no
setting here, and deliberately not even an opt-out: an operator who does not
want an upstream's app variants is expressing a policy, and a handshake knob
that works by misreporting the client would be a control with the wrong name.

A named invocation rides the per-client bridged session, which declares what
its client declared. Lists ride a root session shared by every caller, which
cannot hold two answers — so root sessions, and the list-cache and decode-memo
entries behind them, are keyed by a normalized capability profile. A
federation whose clients are all alike keeps exactly one session per upstream,
as before; a mixed one keeps two, and neither client is served the other's
list. The profile is computed from the extension identifiers fold implements
rather than from the client's raw map: keying on client input would let one
caller declaring a thousand invented extension ids mint a thousand sessions
and cache entries per upstream.

Two notes from implementation. list_changed invalidates every profile's entry
rather than the one whose session heard it — the notification arrives on one
connection and says nothing about the others, but it is the same upstream that
changed for all of them. And the public-view memos became per-profile maps: a
single slot stays correct, since it validates by slice identity, but two
alternating clients would rebuild it on every request.

The design record expected the root-session change to be the expensive part.
It was not: u.roots has been a keyed map since caller-derived credentials
needed one session per principal, so the profile was two lines on rootKey, and
reconnect, resubscribe and drain already worked against the map.

Conformance 40/40; added p50 178.9µs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 3744b80 into main Aug 15, 2026
8 checks passed
@blakebauman
blakebauman deleted the feat/mcp-apps-capability-parity branch August 15, 2026 13:45
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