Skip to content

feat: an app's interface belongs to the upstream that published it - #74

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

blakebauman merged 1 commit into
mainfrom
feat/mcp-apps-ui-routing

Conversation

@blakebauman

Copy link
Copy Markdown
Member

The defect

MCP Apps (SEP-1865) points a tool at an interactive interface through a ui:// resource URI in its _meta.ui. The extension requires that URI to be unique only within one server, and the published starter templates ship one with no server segment at all (ui://get-time/mcp-app.html). Federate two upstreams built from that template and they advertise the same URI for two different interfaces.

fold answered a read of it from whichever upstream listed it last — so a host rendering one team's tool could get another team's app, and which one it got depended on request history:

cold gateway, no resources/list yet  → ui://get-time/mcp-app.html served by "alpha"
after any client's resources/list    → the same URI served by "beta"

Reproduced against two of the official ext-apps example servers, not inferred.

The fix

Mint per namespace on egress, resolve back on ingress:

Surface Behaviour
tools/list _meta.ui.resourceUri and the deprecated flat _meta["ui/resourceUri"] → ui://fold/{namespace}/{rest}
resources/list ui:// entries minted; every other scheme untouched
resources/read minted URI resolves straight to its owner — no probe, no affinity index — and the contents come back under the URI the caller asked with
resources/subscribe / unsubscribe / orphan sweep upstream sees its own URI; the ref-count table stays keyed by the client-facing one, since two upstreams may legitimately publish the same URI
resources/updated minted, so a client can match the notification to its subscription

Policy and the tenant subset are decided on the URI the upstream published, the way a tool is authorized on its bare name — an existing rule keeps working, and a URI fold invented never has to appear in one.

The invariant this touches

fold never rewrites a resource URI. This is the one exception, and it is argued rather than assumed in docs/design-mcp-apps.md: the rule protects identifiers clients persist, while a ui:// pointer is republished on every tools/list. It stays narrow — only the ui:// scheme, a minted form derived from the namespace the operator already chose (stable across restarts, reloads, and instances), and passthrough rewriting nothing. A ui:// URI embedded in a tool result is deliberately not chased: following it there is response-body rewriting, which fold does not do.

The design record also carries the weaker fix this replaced — harvest ownership from tool metadata, keep last-writer-wins, emit a conflict event — and why it was retired: it would have logged the wrong render rather than preventing it.

Verification

  • 8 new tests in gateway/uiresource_test.go against real SDK peers: colliding URIs stay apart, flat and nested pointers agree, only ui:// is rewritten, passthrough untouched, subscribe round-trips under the right URI in both directions, policy decides on the upstream's URI, plus round-trip and split unit tables.
  • Full suite green under -race; golangci-lint clean.
  • Added p50 178.7µs (gate: < 5ms). BenchmarkFederatedListTools measured against the parent commit is identical (30.1k vs 30.4k ns/op, 103 allocs both) — the rewrite happens at list-cache fill and is memoized beside the namespaced views.
  • End-to-end against the two TypeScript ext-apps servers: each tool's interface now reads from its own upstream, cold or warm.

Scope

No config field, no new error code, no new audit method, no schema lockstep. Docs move with it: README gains a feature paragraph and its "Not implemented" bullet narrows to the handshake half of MCP Apps, CLAUDE.md records the exception, roadmap item 15 splits into shipped routing and remaining capability parity.

Not in this PR: capability negotiation (§1 of the design record) — fold declares no client extensions upstream, so an upstream that gates on io.modelcontextprotocol/ui serves fold its text-only fallback. Designed, unbuilt, and insurance rather than a live fix, since nothing shipping gates yet. Two further gaps belong to the extension's specification and are reports to file, not features.

🤖 Generated with Claude Code

MCP Apps (SEP-1865) points a tool at an interactive interface through a
ui:// resource URI in its _meta.ui — a URI the extension requires to be
unique only *within one server*, and which the published starter templates
ship with no server segment at all. Federate two upstreams built from one
template and they advertise the same URI for different interfaces.

fold served a read of that URI from whichever upstream listed it last, so a
host rendering one team's tool could get another team's app — and which one
it got depended on request history: a cold gateway answered from the probe
order, a warmed one from the list. Reproduced against two of the official
ext-apps example servers before this change, and after it each tool reads its
own upstream's bundle, cold or warm.

Those URIs are now minted per namespace as ui://fold/{namespace}/{rest} on
every egress surface — _meta.ui.resourceUri and the deprecated flat form,
resources/list, the URIs a read answers with, and resources/updated for a
subscribed interface — and resolved back to (upstream, original) on read,
subscribe, unsubscribe, and the orphan sweep. Reads route from the URI
itself: no probe, no affinity index, no history.

This is the one exception to fold never rewriting a resource URI, and it is
argued rather than assumed: that rule protects identifiers clients persist,
while a ui:// pointer is republished on every tools/list. It stays narrow —
only the ui:// scheme, a form derived from the namespace the operator already
chose (so it is stable across restarts, reloads, and instances), policy and
audit still deciding on the URI the upstream published, and passthrough
rewriting nothing. A ui:// URI embedded in a tool result is deliberately not
chased: following it there is response-body rewriting.

No config field, no new error code, no new audit method. The rewrite happens
where the list cache refills and is memoized beside the namespaced views, so
the request path is unchanged: added p50 178.7µs against the 5ms gate, and
the federated list benchmark is identical to the parent commit.

Design record, including the weaker fix this replaced and why harvesting
ownership would only have logged the wrong render rather than preventing it:
docs/design-mcp-apps.md.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 51ef3db into main Aug 15, 2026
8 checks passed
@blakebauman
blakebauman deleted the feat/mcp-apps-ui-routing branch August 15, 2026 06:57
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