Repository navigation
feat: carry a client's rendering declaration to the upstream - #75
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
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
ListCachekey, 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_changedinvalidates 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 buglist_changedexists to prevent.The design record expected the root-session change to be the expensive part — endpoint pinning, reload drain, subscription ownership. It was not:
u.rootshas been a keyed map since caller-derived credentials needed one session per principal, so this was two lines onrootKey, and reconnect/resubscribe/drain already worked against the map. The feared duplicateresources/updatedfan-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:tools/listthree times, neither served the other's;tools/callcarries the declaration on the bridged session;Full suite green under
-race,golangci-lintclean, 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