Repository navigation
[P32] apps: serve and read MCP Apps views (SEP-1865) - #339
Merged
Merged
Conversation
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.
This was referenced Nov 25, 2026
varun06
previously approved these changes
Nov 25, 2026
varun06
left a comment
Contributor
There was a problem hiding this comment.
Already reviewed and still looking good.
varun06
approved these changes
Nov 25, 2026
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.
rel/1.0.0in order (previous: P31 (#340) · next: P33 (#338))conformance/p32-appsconformance/p31-server-cards(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)2f3cbb2apps: serve and read MCP Apps views (SEP-1865)b88dd46apps: review fixes001a313apps: second-pass review fixes40f9a16apps: third-pass review fixesSummary
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 typetext/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 withwithAppResources,Tool.uiandResource.uiread 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 theio.modelcontextprotocol/uiextension,modelcontextprotocol/ext-appsatv2.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.uiwrites 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;truealso asks).ToolUIMeta:resourceUri,visibility(ToolUIMeta.Visibility, an open struct:.model,.app)._meta.ui:Tool.ui,Resource.ui,Resource.Content.ui. The raw_metastays the source of truth: setters write the known fields and keep the other keys of_metaand of_meta.ui. Decoding is lenient: a field of the wrong type is read as absent.Tool.uireads the deprecated flat key_meta["ui/resourceUri"]when_meta.uihas noresourceUri; the setter removes it and never writes it.Tool.isVisibleToModelandisCallableFromApp, bothtruewhenvisibilityis absent.UIResourceMeta.CSP.restrictiveDefaultis the policy that the specification requires withoutcsp;CSP.policy()is the specification's construction from the declared origins;UIResourceMeta.contentSecurityPolicypicks one. An origin with whitespace, a control character,;,,,'or"is dropped, so it cannot add a directive or a source keyword.Permissions.policyFeaturesgives the Permissions Policy names for the frame'sallowattribute.Server (
Sources/MCP/Server/Apps.swift,BuiltInResources.swift)UIResource: a validatedui://URI, a name, a title and a description, the HTML as text or bytes (Body), and oneUIResourceMeta, which goes on theresources/listentry and on the content item.UIResource.ValidationError.Server.withAppResources(_:listInResources:): declares the extension and theresourcescapability, answersresources/readof a view before the application's handler, and adds the views to the firstresources/listpage.resources/readbefore the application's handler and join the firstresources/listpage; 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, frominitializeor from the request's_meta.Client (
Sources/MCP/Client/ClientApps.swift)Client.readAppResource(uri:listing:): refuses a URI that is notui://without a request, reads it, and checks the MIME type (text/htmlwithprofile=mcp-app; case, whitespace, quotes and other parameters accepted) and the body (text, or ablobof base64-encoded UTF-8). The effective metadata is the content item's_meta.uior, when it has none, the listing entry's: the givenlisting, or the entry found in up to 100resources/listpages.AppResourceContents(the HTML, the effective metadata, the content item,contentSecurityPolicy);AppResourceErrorwith an open-structReason.Interop (
2f3cbb2)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.ui://interop/weather.htmlwith_meta.uion 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, onwithAppResources. TypeScript:interop/ts-client/server.mjs, withregisterAppResourceandregisterAppTool, which also writes the deprecated flat key._meta.ui, the listing and content metadata, and that the server saw the declaration (getUiCapabilityon TypeScript,clientUISettingson Swift). The Swift client uses the SDK's types; the others read the raw_meta.@modelcontextprotocol/ext-appsis pinned at1.7.5ininterop/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 (snippetsExamples/Snippets/{Server,Client}/Apps.swift); the docs index,rough_edges.md, the migration guide, CHANGELOG,CLAUDE.md;interop/README.mdandinterop/RESULTS.md.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 viewAPI changes
ExtensionID.ui,UIExtensionSettings,Client.Capabilities.uiUIResourceMeta,.CSP,.Permissions,ToolUIMeta,ToolUIMeta.VisibilityTool.ui,Resource.ui,Resource.Content.ui,Tool.isVisibleToModel,Tool.isCallableFromAppUIResourceMeta.CSP.restrictiveDefault,CSP.policy(),UIResourceMeta.contentSecurityPolicy,Permissions.policyFeaturesUIResource,UIResource.Body,UIResource.ValidationError,Server.withAppResources(_:listInResources:),Server.HandlerContext.clientUISettingsClient.readAppResource(uri:listing:),AppResourceContents,AppResourceErrorBehavior changes
resources/listcursor now starts withmcp-resources:instead ofmcp-skills:; a cursor from an earlier server is refused with -32602, as any unknown cursor. The pages are the same.resources/listcursor with a position that the server cannot advance ends the listing instead of repeating.resources/listcursor that is not a string (ornull) 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
appsTotals: 149 client-server cells, 1921 checks.
interop/RESULTS.mdnames6ae1f53, the last commit that changesSources/.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.SkillServerTestsuses the new cursor prefix. At2f3cbb2,swift testpasses 1084 swift-testing tests inMCPTestsand 112 snippet tests on macOS, and 1180 tests on Linux (scripts/ci-linux.sh build-test).Review notes
UIResourceMetagoes 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.connectDomains('none'withoutcsp,'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.tools/listthat varies with the declared settings should have theprivatecache scope; the guides recommend the same tools for every client, with textcontentfor hosts without views.interop/RESULTS.mdnames the commit of theSources/it ran against.Verification
swift test; DocC with warnings as errors; doc coverage;swift scripts/weave.swift --check; the API breakage job.scripts/run-interop.sh --checkon macOS and in the Linux interop job; Linuxscripts/ci-linux.sh build-testand 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.