Skip to content

[P32] apps: serve and read MCP Apps views (SEP-1865) - #339

Merged
jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p32-apps
Nov 25, 2026
Merged

jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p32-apps

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P32 of P0–P35, merged into rel/1.0.0 in order (previous: P31 (#340) · next: P33 (#338))
Branch conformance/p32-apps
Base conformance/p31-server-cards (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits 2f3cbb2 apps: serve and read MCP Apps views (SEP-1865)
b88dd46 apps: review fixes
001a313 apps: second-pass review fixes
40f9a16 apps: third-pass review fixes
Size 41 files, +2742 / -188

Summary

MCP Apps lets a tool show its results in an interactive HTML view that the host renders in a sandboxed frame. A view is a resource with a ui:// URI and the MIME type text/html;profile=mcp-app; a tool refers to it in _meta.ui. The SDK implements the wire between server and host: the server serves views with withAppResources, Tool.ui and Resource.ui read and write the metadata, and the client reads a view with its effective metadata and Content Security Policy. The View-Host bridge (ui/* messages between a view and its host) is not implemented. The wire is the one of the io.modelcontextprotocol/ui extension, modelcontextprotocol/ext-apps at v2.0.4 (7af9a75d), specification/draft/apps.mdx. A new interop profile checks the Swift, Go, Python and TypeScript clients against the Swift server and against a TypeScript server built on the ext-apps server helpers.

Changes

Wire types (Sources/MCP/Base/AppTypes.swift)

  • ExtensionID.ui; UIExtensionSettings (mimeTypes; supports(_:)); Client.Capabilities.ui writes the extension settings.
  • UIResourceMeta: csp, permissions, domain, prefersBorder. UIResourceMeta.CSP: connectDomains, resourceDomains, frameDomains, baseUriDomains. UIResourceMeta.Permissions: camera, microphone, geolocation, clipboardWrite, as presence flags ({} on the wire; true also asks).
  • ToolUIMeta: resourceUri, visibility (ToolUIMeta.Visibility, an open struct: .model, .app).
  • Accessors over _meta.ui: Tool.ui, Resource.ui, Resource.Content.ui. The raw _meta stays the source of truth: setters write the known fields and keep the other keys of _meta and of _meta.ui. Decoding is lenient: a field of the wrong type is read as absent.
  • Tool.ui reads the deprecated flat key _meta["ui/resourceUri"] when _meta.ui has no resourceUri; the setter removes it and never writes it.
  • Tool.isVisibleToModel and isCallableFromApp, both true when visibility is absent.
  • Content Security Policy: UIResourceMeta.CSP.restrictiveDefault is the policy that the specification requires without csp; CSP.policy() is the specification's construction from the declared origins; UIResourceMeta.contentSecurityPolicy picks one. An origin with whitespace, a control character, ;, ,, ' or " is dropped, so it cannot add a directive or a source keyword. Permissions.policyFeatures gives the Permissions Policy names for the frame's allow attribute.

Server (Sources/MCP/Server/Apps.swift, BuiltInResources.swift)

  • UIResource: a validated ui:// URI, a name, a title and a description, the HTML as text or bytes (Body), and one UIResourceMeta, which goes on the resources/list entry and on the content item. UIResource.ValidationError.
  • Server.withAppResources(_:listInResources:): declares the extension and the resources capability, answers resources/read of a view before the application's handler, and adds the views to the first resources/list page.
  • Views and skills share one internal path for built-in resources: ordered sources answer resources/read before the application's handler and join the first resources/list page; later pages continue the application's listing, then each source in order. One cursor (mcp-resources:) holds every position and replaces the skills-only cursor. A cursor position that the server cannot advance (no application handler, or a source the server does not list) is dropped, so a stale or crafted cursor cannot page forever.
  • HandlerContext.clientUISettings: the client's declaration, from initialize or from the request's _meta.

Client (Sources/MCP/Client/ClientApps.swift)

  • Client.readAppResource(uri:listing:): refuses a URI that is not ui:// without a request, reads it, and checks the MIME type (text/html with profile=mcp-app; case, whitespace, quotes and other parameters accepted) and the body (text, or a blob of base64-encoded UTF-8). The effective metadata is the content item's _meta.ui or, when it has none, the listing entry's: the given listing, or the entry found in up to 100 resources/list pages.
  • AppResourceContents (the HTML, the effective metadata, the content item, contentSecurityPolicy); AppResourceError with an open-struct Reason.

Interop (2f3cbb2)

  • Profile apps: every client against the Swift everything-server in both eras, and against the TypeScript server at 2025-11-25, over HTTP and stdio. 22 cells, 110 checks.
  • Fixture: the view ui://interop/weather.html with _meta.ui on the listing entry and the content item; show_weather, which renders in it; refresh_weather, for the view only. Swift: conformance/everything-server/Apps.swift, on withAppResources. TypeScript: interop/ts-client/server.mjs, with registerAppResource and registerAppTool, which also writes the deprecated flat key.
  • Each client declares the extension and checks the tools' _meta.ui, the listing and content metadata, and that the server saw the declaration (getUiCapability on TypeScript, clientUISettings on Swift). The Swift client uses the SDK's types; the others read the raw _meta.
  • @modelcontextprotocol/ext-apps is pinned at 1.7.5 in interop/ts-client (exact version, lockfile with integrity hashes). The interop needs Node 20 or later (ext-apps' minimum).

Docs

  • design/apps.md; the server and client guides (snippets Examples/Snippets/{Server,Client}/Apps.swift); the docs index, rough_edges.md, the migration guide, CHANGELOG, CLAUDE.md; interop/README.md and interop/RESULTS.md.
  • ROADMAP: SEP-1865 Partial (the wire between server and host); the View-Host bridge is under "Planned".

Diagram

sequenceDiagram
    participant H as Host (Client)
    participant S as Server
    H->>S: tools/list
    S-->>H: show_weather, _meta.ui.resourceUri ui://interop/weather.html
    H->>S: resources/read ui://interop/weather.html
    S-->>H: HTML, mimeType text/html with profile=mcp-app, _meta.ui
    Note over H: CSP from _meta.ui, render in a sandboxed frame
    H->>S: tools/call show_weather
    S-->>H: text content, and structuredContent for the view
Loading

API changes

Symbol Notes
ExtensionID.ui, UIExtensionSettings, Client.Capabilities.ui The extension and its settings
UIResourceMeta, .CSP, .Permissions, ToolUIMeta, ToolUIMeta.Visibility Metadata
Tool.ui, Resource.ui, Resource.Content.ui, Tool.isVisibleToModel, Tool.isCallableFromApp Accessors
UIResourceMeta.CSP.restrictiveDefault, CSP.policy(), UIResourceMeta.contentSecurityPolicy, Permissions.policyFeatures Content Security Policy
UIResource, UIResource.Body, UIResource.ValidationError, Server.withAppResources(_:listInResources:), Server.HandlerContext.clientUISettings Server
Client.readAppResource(uri:listing:), AppResourceContents, AppResourceError Client

Behavior changes

  • The skills' resources/list cursor now starts with mcp-resources: instead of mcp-skills:; a cursor from an earlier server is refused with -32602, as any unknown cursor. The pages are the same.
  • A resources/list cursor with a position that the server cannot advance ends the listing instead of repeating.
  • A resources/list cursor that is not a string (or null) is -32602, as in P25 ([P25] skills: SEP-2640 on server and client #346).

Conformance

The harness has no MCP Apps scenario. The everything-server serves the apps fixture; baselines unchanged (empty on every leg). Tier scores 100% at both revisions.

Interop

Profile Cells Checks Result
apps 22 110 all pass, macOS and Linux

Totals: 149 client-server cells, 1921 checks. interop/RESULTS.md names 6ae1f53, the last commit that changes Sources/.

Tests

Tests/MCPTests/AppTests.swift: the specification's examples (tools, resource metadata on the listing and on the content item, permissions, client capabilities), the accessors and the flat key, lenient decoding, the CSP builder and its injection checks, serving (discover, list and read, blob, merging with the application and the skills, cursors), and reading as a host (effective metadata, the listing fallback, errors, MIME types, the client's settings in both eras). Snippet tests for both guides. SkillServerTests uses the new cursor prefix. At 2f3cbb2, swift test passes 1084 swift-testing tests in MCPTests and 112 snippet tests on macOS, and 1180 tests on Linux (scripts/ci-linux.sh build-test).

Review notes

  • One UIResourceMeta goes on both the listing entry and the content item. The specification prefers the content item; the listing entry lets a host review the metadata before it reads the view.
  • The two specification texts differ for an empty connectDomains ('none' without csp, 'self' with it); the SDK follows each text. The reference host in ext-apps is looser ('unsafe-eval', blob:, worker-src); the SDK does not copy it.
  • SEP-2567 forbids lists that vary per connection, not per request input. A tools/list that varies with the declared settings should have the private cache scope; the guides recommend the same tools for every client, with text content for hosts without views.
  • ext-apps 2.x needs the TypeScript SDK v2 packages, which also serve 2025-11-25 only; 1.7.5, the last 1.x release, runs on the TypeScript SDK that the interop already pins, with the same wire for these checks.
  • Two commits, so that interop/RESULTS.md names the commit of the Sources/ it ran against.

Verification

  • swift test; DocC with warnings as errors; doc coverage; swift scripts/weave.swift --check; the API breakage job.
  • Every conformance leg for client and server; both tier scores.
  • scripts/run-interop.sh --check on macOS and in the Linux interop job; Linux scripts/ci-linux.sh build-test and the fuzz targets.

AI usage disclosure: the changes, the tests, the commit messages and this description were written with Claude Opus 5.5 and reviewed by the authors.

MCP Apps lets a tool show its results in an HTML view that the host
renders in a sandboxed frame. The wire is the one of the
io.modelcontextprotocol/ui extension, modelcontextprotocol/ext-apps at
v2.0.4 (7af9a75d), specification/draft/apps.mdx. The SDK implements the
wire between server and host, not the View-Host bridge.

Types: ExtensionID.ui, UIExtensionSettings (mimeTypes), UIResourceMeta
(csp, permissions as presence flags, domain, prefersBorder) and
ToolUIMeta (resourceUri, visibility as an open struct). Tool.ui,
Resource.ui and Resource.Content.ui read and write _meta.ui; the raw
_meta stays the source of truth and keeps unknown keys, and decoding is
lenient per field. Tool.ui reads the deprecated flat key
_meta["ui/resourceUri"] when _meta.ui has no resourceUri, and never
writes it. Tool.isVisibleToModel and isCallableFromApp default to true.

Server: withAppResources(_:listInResources:) serves UIResources (a
ui:// URI, HTML as text or bytes, one UIResourceMeta on the listing
entry and on the content item), and declares the extension and
resources. Views and skills now share one internal path for built-in
resources: ordered sources answer resources/read before the
application's handler and join the first resources/list page, with one
cursor for every position. A cursor position that the server cannot
advance is dropped, so a stale or crafted cursor cannot page forever.
HandlerContext.clientUISettings is the client's declaration, from
initialize or from the request's _meta.

Client: Client.Capabilities.ui declares the extension.
readAppResource(uri:listing:) checks the URI, the MIME type and the
body, and returns the effective metadata: the content item's _meta.ui,
or else the listing entry's, found in up to 100 pages when not given.
UIResourceMeta.CSP.policy() builds the specification's policy, and
restrictiveDefault is its policy without csp; origins that could add a
directive or a keyword are dropped.

Tests: the specification's examples, the accessors, the CSP builder,
serving and merging with skills, and reading as a host in both eras.
The guides, design/apps.md and ROADMAP (Partial: the bridge is
Planned) describe it.

The apps profile runs the Swift, Go, Python and TypeScript clients
against the Swift everything-server, in both eras, and against the
TypeScript server, at 2025-11-25, over HTTP and stdio: 22 cells, all
passing.

Both servers serve the same fixture: the view
ui://interop/weather.html with _meta.ui on the listing entry and on the
content item, show_weather, which renders in it, and refresh_weather,
for the view only. The Swift fixture is
conformance/everything-server/Apps.swift, on withAppResources; the
conformance legs do not change. The TypeScript server registers it
with the ext-apps server helpers (registerAppResource,
registerAppTool, which also writes the deprecated flat key).

Each client declares io.modelcontextprotocol/ui with the HTML MIME type
and checks the tools' _meta.ui, the listing and content metadata, and
that the server saw the declaration (getUiCapability on TypeScript,
clientUISettings on Swift). The Swift client uses the SDK's types; the
others read the raw _meta.

ext-apps is pinned at 1.7.5 in interop/ts-client: 2.x needs the
TypeScript SDK v2 packages, which also serve 2025-11-25 only, and 1.7.5
runs on the pinned SDK with the same wire for these checks. It needs
Node 20. RESULTS.md and the findings record the run.
- A merged resources/list page (the application's page with views and
  skills) now has the shortest ttlMs of its pages, and cacheScope
  private when any page is private, instead of the application's hints
  covering entries whose own page allowed less caching.
- UIResource requires the ui:// scheme in lowercase: views are found by
  their exact URI, so a view registered as UI://x was not served for a
  read of ui://x and vice versa.
- readAppResource uses the listing entry's metadata only when the
  content item's _meta.ui is absent or null, as the specification's
  `??` does; a present but malformed value now gives no metadata and
  the restrictive default policy, not the listing's possibly looser
  policy.
- Document that a ResourceListChangedNotification after a second
  withAppResources needs resources.listChanged: withAppResources
  declares resources without it, and listen streams carry the
  notification only when it is declared.
- readAppResource returns the view with no metadata, and so the
  restrictive default policy, when the resources/list fallback fails:
  the listing only adds metadata, so it should not fail the read.
  Cancellation still propagates.
- AppResourceContents has a public memberwise init, so callers can build
  one, for example in tests.
- CSP.policy() says it uses the declared sources as given: a declared *
  or scheme-only source allows any origin, and a host that does not trust
  the declarations filters them first.
- The ui setters say which keys they keep: other top-level keys of
  _meta.ui, with csp and permissions written as modelled;
  Client.Capabilities.ui replaces the extension's settings object.
- Test that a second withAppResources replaces the views for read and
  list, with skills installed in between, and that the views stay before
  the skills.

- The prerequisites of scripts/run-interop.sh, in its header, interop/README.md
  and CONTRIBUTING.md, list perl and python3, which the script checks for:
  perl runs the time limit and python3 the report. Node was already listed
  except in CONTRIBUTING.md.
- readAppResource refuses a URI that does not start with ui:// in
  lowercase, without a request, as UIResource does: views are looked up
  by the exact URI, so UI://x went to the server and failed there with
  a not-found error or missingContent.
- UIExtensionSettings(_:) reads the extension as declared only when its
  value is an object, as SkillsSettings(_:) does: a null, false, string
  or array value no longer declares a host that renders views.
- The ui setters encode _meta.ui with Value.preservingStrings, and
  CSP and ToolUIMeta decode their lists as Value.Preserved: a string
  that is a data: URL, in visibility, a CSP list or domain, stays the
  string as written instead of being re-encoded, or dropped on read.
- A merged resources/list page counts a page without ttlMs or
  cacheScope with the server's hint for resources/list (cacheHints,
  else defaultCacheHint, .uncached by default), the hint that page
  would get alone. An application page that relied on .uncached
  inherited a skill catalog's public scope and longer ttlMs. The views'
  page has no hints, so it counts with the same hint.
- Tool.ui says that its setter keeps the other top-level keys of
  _meta.ui, as Resource.ui and Resource.Content.ui say.
varun06
varun06 previously approved these changes Nov 25, 2026

@varun06 varun06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed and still looking good.

Base automatically changed from conformance/p31-server-cards to rel/1.0.0 November 25, 2026 12:54
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:54

The base branch was changed.

@jeanmatthieu
jeanmatthieu merged commit eb0d228 into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p32-apps branch November 25, 2026 12:54
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.

2 participants