@doubao-dev/cli 1.0.0-rc.0 → 1.0.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +12 -5
  2. package/bin/run.js +1 -6
  3. package/dist/691.js +96 -0
  4. package/dist/691.js.LICENSE.txt +13 -0
  5. package/dist/build.js +1 -0
  6. package/dist/categories.js +1 -1
  7. package/dist/command.js +9 -2
  8. package/dist/command~1.js +4 -4
  9. package/dist/command~2.js +1 -1
  10. package/dist/command~3.js +2 -1
  11. package/dist/command~4.js +1 -1
  12. package/dist/command~5.js +6 -2
  13. package/dist/dist.js +1 -1
  14. package/dist/draft.js +2 -2
  15. package/dist/index.d.ts +892 -11
  16. package/dist/index.js +1 -1
  17. package/dist/main.d.ts +892 -11
  18. package/dist/main.js +1 -1
  19. package/dist/mcp-apps-inspector.js +1 -0
  20. package/dist/multipart-parser.js +2 -0
  21. package/dist/open.js +2 -0
  22. package/dist/plugin.js +3 -1
  23. package/dist/plugin.js.LICENSE.txt +58 -0
  24. package/dist/preview.js +9 -0
  25. package/dist/progress.js +1 -0
  26. package/dist/ratatui-ui.js +1 -1
  27. package/dist/rslib-runtime.js +1 -0
  28. package/dist/session.js +2 -1
  29. package/dist/session.js.LICENSE.txt +1 -0
  30. package/dist/skills/doubao-plugin-cli/SKILL.md +44 -40
  31. package/dist/skills/doubao-plugin-cli/references/cli/development.md +126 -0
  32. package/dist/skills/doubao-plugin-cli/references/cli/project.md +188 -0
  33. package/dist/skills/doubao-plugin-cli/references/cli/release.md +144 -0
  34. package/dist/skills/doubao-plugin-cli/references/examples/todo-example.md +88 -0
  35. package/dist/skills/doubao-plugin-cli/references/examples/workbench-example.md +130 -0
  36. package/dist/skills/doubao-plugin-cli/references/protocols/business-skills.md +49 -0
  37. package/dist/skills/doubao-plugin-cli/references/protocols/cli-connectors.md +56 -0
  38. package/dist/skills/doubao-plugin-cli/references/protocols/managed-agents.md +46 -0
  39. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-apps/integration.md +186 -0
  40. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-apps/runtime.md +318 -0
  41. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-apps/workbench.md +180 -0
  42. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-auth.md +73 -0
  43. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-config.md +145 -0
  44. package/dist/skills/doubao-plugin-cli/references/protocols/mcp-events.md +260 -0
  45. package/dist/skills/doubao-plugin-cli/references/protocols/plugin-json.md +95 -0
  46. package/dist/skills/doubao-plugin-cli/references/protocols/workbench.md +120 -0
  47. package/dist/skills/doubao-plugin-cli/references/upstream/SOURCES.md +24 -0
  48. package/dist/skills/doubao-plugin-cli/references/upstream/mcp-apps.LICENSE +216 -0
  49. package/dist/skills/doubao-plugin-cli/references/upstream/mcp-apps.mdx +1768 -0
  50. package/dist/skills/doubao-plugin-cli/references/upstream/mcp-events.LICENSE +216 -0
  51. package/dist/skills/doubao-plugin-cli/references/upstream/mcp-events.md +1231 -0
  52. package/dist/skills/doubao-plugin-cli/references/upstream/standard-webhooks.LICENSE +201 -0
  53. package/dist/skills/doubao-plugin-cli/references/upstream/standard-webhooks.md +349 -0
  54. package/dist/templates/standard/AGENTS.md +1 -1
  55. package/dist/templates/workbench/README.md.template +9 -0
  56. package/dist/templates/workbench/com.doubao/workbench/manifest.json +10 -0
  57. package/dist/uninstall.js +1 -1
  58. package/dist/versions.js +1 -1
  59. package/dist/versions~1.js +1 -0
  60. package/dist/web/index.html +1 -0
  61. package/dist/web/sandbox-proxy.html +101 -0
  62. package/dist/web/static/css/index.b3102f16b9.css +1 -0
  63. package/dist/web/static/js/155.747f5232dc.js +69 -0
  64. package/dist/web/static/js/async/970.86106314b5.js +1 -0
  65. package/dist/web/static/js/index.c1186260b9.js +4 -0
  66. package/dist/web/static/js/lib-react.00514652bf.js +2 -0
  67. package/dist/web/static/js/lib-react.00514652bf.js.LICENSE.txt +39 -0
  68. package/dist/workbench-search.js +1 -0
  69. package/dist/xdg-open +1267 -0
  70. package/package.json +17 -16
  71. package/dist/472.js +0 -9
  72. package/dist/schema.js +0 -1
  73. package/dist/skills/doubao-plugin-cli/references/cli-connectors.md +0 -29
  74. package/dist/skills/doubao-plugin-cli/references/development.md +0 -29
  75. package/dist/skills/doubao-plugin-cli/references/mcp-apps.md +0 -40
  76. package/dist/skills/doubao-plugin-cli/references/mcp-auth.md +0 -23
  77. package/dist/skills/doubao-plugin-cli/references/project-config.md +0 -139
  78. package/dist/skills/doubao-plugin-cli/references/upload.md +0 -71
@@ -0,0 +1,1768 @@
1
+ <!-- For full edit history, see specification/draft/apps.mdx -->
2
+
3
+ # SEP-1865: MCP Apps: Interactive User Interfaces for MCP
4
+
5
+ **Track:** Extensions
6
+
7
+ **Authors:** Ido Salomon, Liad Yosef, Olivier Chafik, Jerome Swannack, Jonathan Hefner, Anton Pidkuiko, Nick Cooper, Bryan Ashley, Alexi Christakis
8
+
9
+ **Status:** Stable (2026-01-26)
10
+
11
+ **Created:** 2025-11-21
12
+
13
+ ## Abstract
14
+
15
+ This SEP proposes an extension (per SEP-1724) to MCP that enables servers to deliver interactive user interfaces to hosts. MCP Apps introduces a standardized pattern for declaring UI resources via the `ui://` URI scheme, associating them with tools through metadata, and facilitating bidirectional communication between the UI and the host using MCP's JSON-RPC base protocol. This extension addresses the growing community need for rich, interactive experiences in MCP-enabled applications, maintaining security, auditability, and alignment with MCP's core architecture. The initial specification focuses on HTML resources (`text/html;profile=mcp-app`) with a clear path for future extensions.
16
+
17
+ ## Motivation
18
+
19
+ MCP lacks a standardized way for servers to deliver rich, interactive user interfaces to hosts. This gap blocks many use cases that require visual presentation and interactivity that goes beyond plain text or structured data. As more hosts adopt this capability, there's a growing risk of fragmentation and interoperability challenges.
20
+
21
+ [MCP-UI](https://mcpui.dev/) has demonstrated the viability and value of MCP apps built on UI resources and serves as a community playground for the UI spec and SDK. Fuelled by a dedicated community, it developed the bi-directional communication model and the HTML, external URL, and remote DOM content types. MCP-UI's adopters, including hosts and providers such as Postman, HuggingFace, Shopify, Goose, and ElevenLabs, have provided critical insights and contributions to the community.
22
+
23
+ OpenAI's Apps SDK, launched in November 2025, further validated the demand for rich UI experiences within conversational AI interfaces. The Apps SDK enables developers to build rich, interactive applications inside ChatGPT using MCP as its backbone.
24
+
25
+ The architecture of both the Apps SDK and MCP-UI have both significantly informed the design of this specification.
26
+
27
+ However, without formal standardization:
28
+
29
+ - Servers cannot reliably expect UI support via MCP
30
+ - Each host may implement slightly different behaviors
31
+ - Security and auditability patterns are inconsistent
32
+ - Developers must maintain separate implementations or adapters for different hosts (e.g., MCP-UI vs. Apps SDK)
33
+
34
+ This SEP addresses the current limitations through an optional, backwards-compatible extension that unifies the approaches pioneered by MCP-UI and the Apps SDK into a single, open standard.
35
+
36
+ ## Specification
37
+
38
+ ### Extension Identifier
39
+
40
+ This extension is identified as: `io.modelcontextprotocol/ui`
41
+
42
+ ### Overview
43
+
44
+ MCP Apps extends the Model Context Protocol to enable servers to deliver interactive user interfaces to hosts. This extension introduces:
45
+
46
+ - **UI Resources:** Predeclared resources using the `ui://` URI scheme
47
+ - **Tool-UI Linkage:** Tools reference UI resources via metadata
48
+ - **Bidirectional Communication:** UI iframes communicate with hosts using standard MCP JSON-RPC protocol
49
+ - **Security Model:** Mandatory iframe sandboxing with auditable communication
50
+
51
+ This specification focuses on HTML content (`text/html;profile=mcp-app`) as the initial content type, with extensibility for future formats.
52
+
53
+ As an extension, MCP Apps is optional and must be explicitly negotiated between clients and servers through the extension capabilities mechanism (see Capability Negotiation section).
54
+
55
+ ### UI Resource Format
56
+
57
+ UI resources are declared using the standard MCP resource pattern with specific conventions:
58
+
59
+ ```typescript
60
+ interface UIResource {
61
+ /**
62
+ * Unique identifier for the UI resource
63
+ *
64
+ * MUST use the `ui://` URI scheme to distinguish UI resources from other
65
+ * MCP resource types.
66
+ *
67
+ * @example
68
+ * "ui://weather-dashboard"
69
+ */
70
+ uri: string;
71
+
72
+ /**
73
+ * Human-readable display name for the UI resource
74
+ *
75
+ * Used for listing and identifying the resource in host interfaces.
76
+ *
77
+ * @example
78
+ * "Weather Dashboard"
79
+ */
80
+ name: string;
81
+
82
+ /**
83
+ * Optional description of the UI resource's purpose and functionality
84
+ *
85
+ * Provides context about what the UI does and when to use it.
86
+ *
87
+ * @example
88
+ * "Interactive weather visualization with real-time updates"
89
+ */
90
+ description?: string;
91
+
92
+ /**
93
+ * MIME type of the UI content
94
+ *
95
+ * SHOULD be `text/html;profile=mcp-app` for HTML-based UIs in the initial MVP.
96
+ * Other content types are reserved for future extensions.
97
+ *
98
+ * @example
99
+ * "text/html;profile=mcp-app"
100
+ */
101
+ mimeType: string;
102
+
103
+ /**
104
+ * Resource metadata for security and rendering configuration
105
+ *
106
+ * Includes Content Security Policy configuration, dedicated domain settings,
107
+ * and visual preferences.
108
+ */
109
+ _meta?: {
110
+ ui?: UIResourceMeta;
111
+ }
112
+ }
113
+
114
+ interface McpUiResourceCsp {
115
+ /**
116
+ * Origins for network requests (fetch/XHR/WebSocket)
117
+ *
118
+ * - Empty or omitted = no external connections (secure default)
119
+ * - Maps to CSP `connect-src` directive
120
+ *
121
+ * @example
122
+ * ["https://api.weather.com", "wss://realtime.service.com"]
123
+ */
124
+ connectDomains?: string[],
125
+ /**
126
+ * Origins for static resources (images, scripts, stylesheets, fonts, media)
127
+ *
128
+ * - Empty or omitted = no external resources (secure default)
129
+ * - Wildcard subdomains supported: `https://*.example.com`
130
+ * - Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives
131
+ *
132
+ * @example
133
+ * ["https://cdn.jsdelivr.net", "https://*.cloudflare.com"]
134
+ */
135
+ resourceDomains?: string[],
136
+ /**
137
+ * Origins for nested iframes
138
+ *
139
+ * - Empty or omitted = no nested iframes allowed (`frame-src 'none'`)
140
+ * - Maps to CSP `frame-src` directive
141
+ *
142
+ * @example
143
+ * ["https://www.youtube.com", "https://player.vimeo.com"]
144
+ */
145
+ frameDomains?: string[],
146
+ /**
147
+ * Allowed base URIs for the document
148
+ *
149
+ * - Empty or omitted = only same origin allowed (`base-uri 'self'`)
150
+ * - Maps to CSP `base-uri` directive
151
+ *
152
+ * @example
153
+ * ["https://cdn.example.com"]
154
+ */
155
+ baseUriDomains?: string[],
156
+ }
157
+
158
+ interface UIResourceMeta {
159
+ /**
160
+ * Content Security Policy configuration
161
+ *
162
+ * Servers declare which external origins their UI needs to access.
163
+ * Hosts use this to enforce appropriate CSP headers.
164
+ */
165
+ csp?: McpUiResourceCsp,
166
+ /**
167
+ * Sandbox permissions requested by the UI
168
+ *
169
+ * Servers declare which browser capabilities their UI needs.
170
+ * Hosts MAY honor these by setting appropriate iframe `allow` attributes.
171
+ * Apps SHOULD NOT assume permissions are granted; use JS feature detection as fallback.
172
+ */
173
+ permissions?: {
174
+ /**
175
+ * Request camera access
176
+ *
177
+ * Maps to Permission Policy `camera` feature
178
+ */
179
+ camera?: {},
180
+ /**
181
+ * Request microphone access
182
+ *
183
+ * Maps to Permission Policy `microphone` feature
184
+ */
185
+ microphone?: {},
186
+ /**
187
+ * Request geolocation access
188
+ *
189
+ * Maps to Permission Policy `geolocation` feature
190
+ */
191
+ geolocation?: {},
192
+ /**
193
+ * Request clipboard write access
194
+ *
195
+ * Maps to Permission Policy `clipboard-write` feature
196
+ */
197
+ clipboardWrite?: {},
198
+ },
199
+ /**
200
+ * Dedicated origin for view
201
+ *
202
+ * Optional domain for the view's sandbox origin. Useful when views need
203
+ * stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
204
+ *
205
+ * **Host-dependent:** The format and validation rules for this field are
206
+ * determined by each host. Servers MUST consult host-specific documentation
207
+ * for the expected domain format. Common patterns include:
208
+ * - Hash-based subdomains (e.g., `{hash}.claudemcpcontent.com`)
209
+ * - URL-derived subdomains (e.g., `www-example-com.oaiusercontent.com`)
210
+ *
211
+ * If omitted, Host uses default sandbox origin (typically per-conversation).
212
+ *
213
+ * @example
214
+ * "a904794854a047f6.claudemcpcontent.com"
215
+ * @example
216
+ * "www-example-com.oaiusercontent.com"
217
+ */
218
+ domain?: string,
219
+ /**
220
+ * Visual boundary preference
221
+ *
222
+ * Boolean controlling whether a visible border and background is provided by the host. Specifying an
223
+ * explicit value for this is recommended because hosts' defaults may vary.
224
+ *
225
+ * - `true`: Request visible border + background
226
+ * - `false`: Request no visible border + background
227
+ * - omitted: host decides border
228
+ */
229
+ prefersBorder?: boolean,
230
+ }
231
+ ```
232
+
233
+ The resource content is returned via `resources/read`:
234
+
235
+ ```typescript
236
+ // resources/read response for UI resource
237
+ {
238
+ contents: [{
239
+ uri: string; // Matching UI resource URI
240
+ mimeType: "text/html;profile=mcp-app"; // MUST be "text/html;profile=mcp-app"
241
+ text?: string; // HTML content as string
242
+ blob?: string; // OR base64-encoded HTML
243
+ _meta?: {
244
+ ui?: {
245
+ csp?: {
246
+ connectDomains?: string[]; // Origins for network requests (fetch/XHR/WebSocket).
247
+ resourceDomains?: string[]; // Origins for static resources (scripts, images, styles, fonts).
248
+ frameDomains?: string[]; // Origins for nested iframes (frame-src directive).
249
+ baseUriDomains?: string[]; // Allowed base URIs for the document (base-uri directive).
250
+ };
251
+ permissions?: {
252
+ camera?: {}; // Request camera access
253
+ microphone?: {}; // Request microphone access
254
+ geolocation?: {}; // Request geolocation access
255
+ clipboardWrite?: {}; // Request clipboard write access
256
+ };
257
+ domain?: string;
258
+ prefersBorder?: boolean;
259
+ };
260
+ };
261
+ }];
262
+ }
263
+ ```
264
+
265
+ #### Content Requirements:
266
+
267
+ - URI MUST start with `ui://` scheme
268
+ - `mimeType` MUST be `text/html;profile=mcp-app` (other types reserved for future extensions)
269
+ - Content MUST be provided via either `text` (string) or `blob` (base64-encoded)
270
+ - Content MUST be valid HTML5 document
271
+
272
+ #### Host Behavior:
273
+
274
+ - **CSP Enforcement:** Host MUST construct CSP headers based on declared domains
275
+ - **Restrictive Default:** If `ui.csp` is omitted, Host MUST use:
276
+
277
+ ```
278
+ default-src 'none';
279
+ script-src 'self' 'unsafe-inline';
280
+ style-src 'self' 'unsafe-inline';
281
+ img-src 'self' data:;
282
+ media-src 'self' data:;
283
+ connect-src 'none';
284
+ ```
285
+
286
+ - **No Loosening:** Host MAY further restrict but MUST NOT allow undeclared domains
287
+ - **Audit Trail:** Host SHOULD log CSP configurations for security review
288
+
289
+ Example:
290
+
291
+ ```json
292
+ // Resource declaration
293
+ {
294
+ "uri": "ui://weather-server/dashboard-template",
295
+ "name": "weather_dashboard",
296
+ "description": "Interactive weather dashboard view",
297
+ "mimeType": "text/html;profile=mcp-app"
298
+ }
299
+
300
+ // Resource content with metadata
301
+ {
302
+ "contents": [{
303
+ "uri": "ui://weather-server/dashboard-template",
304
+ "mimeType": "text/html;profile=mcp-app",
305
+ "text": "<!DOCTYPE html><html>...</html>",
306
+ "_meta": {
307
+ "ui" : {
308
+ "csp": {
309
+ "connectDomains": ["https://api.openweathermap.org"],
310
+ "resourceDomains": ["https://cdn.jsdelivr.net"]
311
+ },
312
+ "prefersBorder": true
313
+ }
314
+ }
315
+ }]
316
+ }
317
+ ```
318
+
319
+ ### Resource Discovery
320
+
321
+ Tools are associated with UI resources through the `_meta.ui` field:
322
+
323
+ ```typescript
324
+ interface McpUiToolMeta {
325
+ /** URI of UI resource for rendering tool results */
326
+ resourceUri?: string;
327
+ /**
328
+ * Who can access this tool. Default: ["model", "app"]
329
+ * - "model": Tool visible to and callable by the agent
330
+ * - "app": Tool callable by the app from this server only
331
+ */
332
+ visibility?: Array<"model" | "app">;
333
+ }
334
+
335
+ interface Tool {
336
+ name: string;
337
+ description: string;
338
+ inputSchema: object;
339
+ _meta?: {
340
+ ui?: McpUiToolMeta;
341
+ /** @deprecated Use `ui.resourceUri` instead. Will be removed before GA. */
342
+ "ui/resourceUri"?: string;
343
+ };
344
+ }
345
+ ```
346
+
347
+ > **Deprecation notice:** The flat `_meta["ui/resourceUri"]` format is deprecated. Use `_meta.ui.resourceUri` instead. The deprecated format will be removed before GA.
348
+
349
+ Example (tool visible to both model and app):
350
+
351
+ ```json
352
+ {
353
+ "name": "get_weather",
354
+ "description": "Get current weather for a location",
355
+ "inputSchema": {
356
+ "type": "object",
357
+ "properties": {
358
+ "location": { "type": "string" }
359
+ }
360
+ },
361
+ "_meta": {
362
+ "ui": {
363
+ "resourceUri": "ui://weather-server/dashboard-template",
364
+ "visibility": ["model", "app"]
365
+ }
366
+ }
367
+ }
368
+ ```
369
+
370
+ Example (app-only tool, hidden from model):
371
+
372
+ ```json
373
+ {
374
+ "name": "refresh_dashboard",
375
+ "description": "Refresh dashboard data",
376
+ "inputSchema": { "type": "object" },
377
+ "_meta": {
378
+ "ui": {
379
+ "resourceUri": "ui://weather-server/dashboard-template",
380
+ "visibility": ["app"]
381
+ }
382
+ }
383
+ }
384
+ ```
385
+
386
+ #### Behavior:
387
+
388
+ - If `ui.resourceUri` is present and host supports MCP Apps, host renders tool results using the specified UI resource
389
+ - If host does not support MCP Apps, tool behaves as standard tool (text-only fallback)
390
+ - Resource MUST exist on the server
391
+ - Host MUST use `resources/read` to fetch the referenced resource URI
392
+ - Host MAY prefetch and cache UI resource content for performance optimization
393
+ - Since UI resources are primarily discovered through tool metadata, Servers MAY omit UI-only resources from `resources/list` and `notifications/resources/list_changed`
394
+
395
+ #### Visibility:
396
+
397
+ - `visibility` defaults to `["model", "app"]` if omitted
398
+ - `"model"`: Tool is visible to and callable by the agent
399
+ - `"app"`: Tool is callable by the app from the same server connection only
400
+ - **tools/list behavior:** Host MUST NOT include tools in the agent's tool list when their visibility does not include `"model"` (e.g., `visibility: ["app"]`)
401
+ - **tools/call behavior:** Host MUST reject `tools/call` requests from apps for tools that don't include `"app"` in visibility
402
+ - Cross-server tool calls are always blocked for app-only tools
403
+
404
+ #### Benefits:
405
+
406
+ - **Performance:** Host can preload templates before tool execution
407
+ - **Security:** Host can review UI templates during connection setup
408
+ - **Caching:** Separate template (static) from data (dynamic)
409
+ - **Auditability:** All UI resources are enumerable and inspectable
410
+
411
+ ### Communication Protocol
412
+
413
+ MCP Apps uses JSON-RPC 2.0 over `postMessage` for iframe-host communication. UI capabilities (e.g., tool call, prompt, etc.) will reuse MCP’s existing protocol. In the future, we may choose to enrich the communication protocol with additional MCP capabilities.
414
+
415
+ ### Transport Layer
416
+
417
+ Conceptually, UI iframes act as MCP clients, connecting to the host via a `postMessage` transport:
418
+
419
+ ```typescript
420
+ // UI iframe initializes MCP client
421
+ const transport = new MessageTransport(window.parent);
422
+ const client = new Client({ name: "ui-view", version: "1.0.0" });
423
+ await client.connect(transport);
424
+ ```
425
+
426
+ Note that you don’t need an SDK to “talk MCP” with the host:
427
+
428
+ ```typescript
429
+ let nextId = 1;
430
+ function sendRequest(method: string, params: any) {
431
+ const id = nextId++;
432
+ window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, '*');
433
+ return new Promise((resolve, reject) => {
434
+ window.addEventListener('message', function listener(event) {
435
+ const data: JSONRPCMessage = event.data;
436
+ if (event.data?.id === id) {
437
+ window.removeEventListener('message', listener);
438
+ if (event.data?.result) {
439
+ resolve(event.data?.result);
440
+ } else if (event.data?.error) {
441
+ reject(new Error(event.data.error));
442
+ }
443
+ } else {
444
+ reject(new Error(`Unsupported message: ${JSON.stringify(data)}`));
445
+ }
446
+ });
447
+ });
448
+ }
449
+ function sendNotification(method: string, params: any) {
450
+ window.parent.postMessage({ jsonrpc: "2.0", method, params }, '*');
451
+ }
452
+ function onNotification(method: string, handler: (params: any) => void) {
453
+ window.addEventListener('message', function listener(event) {
454
+ if (event.data?.method === method) {
455
+ handler(event.data.params);
456
+ }
457
+ });
458
+ }
459
+
460
+
461
+ const initializeResult = await sendRequest("initialize", {
462
+ capabilities: {},
463
+ clientInfo: {name: "My UI", version: "1.0.0"},
464
+ protocolVersion: "2026-01-26",
465
+ });
466
+ ```
467
+
468
+ Hosts act as MCP servers (that can proxy the actual MCP server), receiving and handling requests from UI iframes.
469
+
470
+ ### Sandbox proxy
471
+
472
+ If the Host is a web page, it MUST wrap the View and communicate with it through an intermediate Sandbox proxy.
473
+
474
+ 1. The Host and the Sandbox MUST have different origins.
475
+ 2. The Sandbox MUST have the following permissions: `allow-scripts`, `allow-same-origin`.
476
+ 3. The Sandbox MUST send a `ui/notifications/sandbox-proxy-ready` notification to the host when it's ready to process an `ui/notifications/sandbox-resource-ready` notification.
477
+ 4. Once the Sandbox is ready, the Host MUST send the raw HTML resource to load in a `ui/notifications/sandbox-resource-ready` notification.
478
+ 5. The Sandbox MUST load the raw HTML of the View with CSP settings that:
479
+ - Enforce the domains declared in `ui.csp` metadata
480
+ - If `frameDomains` is provided, allow nested iframes from declared origins; otherwise use `frame-src 'none'`
481
+ - If `baseUriDomains` is provided, allow base URIs from declared origins; otherwise use `base-uri 'self'`
482
+ - Block dangerous features (`object-src 'none'`)
483
+ - Apply restrictive defaults if no CSP metadata is provided
484
+ - If `permissions` is declared, the Sandbox MAY set the inner iframe's `allow` attribute accordingly
485
+ 6. The Sandbox MUST forward messages sent by the Host to the View, and vice versa, for any method that doesn't start with `ui/notifications/sandbox-`. This includes lifecycle messages, e.g., `ui/initialize` request & `ui/notifications/initialized` notification both sent by the View. The Host MUST NOT send any request or notification to the View before it receives an `initialized` notification.
486
+ 7. The Sandbox SHOULD NOT create/send any requests to the Host or to the View (this would require synthesizing new request ids).
487
+ 8. The Host MAY forward any message from the View (coming via the Sandbox) to the MCP Apps server, for any method that doesn't start with `ui/`. While the Host SHOULD ensure the View's MCP connection is spec-compliant, it MAY decide to block some messages or subject them to further user approval.
488
+
489
+ ### Standard MCP Messages
490
+
491
+ UI iframes can use the following subset of standard MCP protocol messages:
492
+
493
+ **Tools:**
494
+
495
+ - `tools/call` - Execute a tool on the MCP server
496
+
497
+ **Resources:**
498
+
499
+ - `resources/read` - Read resource content
500
+
501
+ **Notifications:**
502
+
503
+ - `notifications/message` - Log messages to host
504
+
505
+ **Lifecycle:**
506
+
507
+ - `ui/initialize` → `ui/notifications/initialized` - MCP-like handshake (replaces custom iframe-ready pattern in MCP-UI)
508
+ - `ping` - Connection health check
509
+
510
+ ### App Capabilities in `ui/initialize`
511
+
512
+ When the View sends an `ui/initialize` request to the Host, it MUST include its capabilities in the `appCapabilities` field:
513
+
514
+ ```typescript
515
+ interface McpUiAppCapabilities {
516
+ /** Experimental features (structure TBD). */
517
+ experimental?: {};
518
+ /** App exposes MCP-style tools that the host can call. */
519
+ tools?: {
520
+ /** App supports tools/list_changed notifications. */
521
+ listChanged?: boolean;
522
+ };
523
+ /**
524
+ * Display modes the app supports. See Display Modes section for details.
525
+ * @example ["inline", "fullscreen"]
526
+ */
527
+ availableDisplayModes?: Array<"inline" | "fullscreen" | "pip">;
528
+ }
529
+ ```
530
+
531
+ ### Host Context in `McpUiInitializeResult`
532
+
533
+ When the View sends an `ui/initialize` request to the Host, the Host SHOULD include UI-specific context in the `McpUiInitializeResult`'s `hostContext` field:
534
+
535
+ ```typescript
536
+ interface HostContext {
537
+ /** Metadata of the tool call that instantiated the View */
538
+ toolInfo?: {
539
+ /** JSON-RPC id of the tools/call request */
540
+ id?: RequestId,
541
+ /** Contains name, inputSchema, etc… */
542
+ tool: Tool,
543
+ };
544
+ /** Current color theme preference */
545
+ theme?: "light" | "dark";
546
+ /** Style configuration for theming. See Theming section for standardized variable names. */
547
+ styles?: {
548
+ /** CSS variables for theming */
549
+ variables?: Record<McpUiStyleVariableKey, string | undefined>;
550
+ /** CSS blocks that Views can inject */
551
+ css?: {
552
+ /** CSS for font loading (@font-face rules or @import statements) */
553
+ fonts?: string;
554
+ };
555
+ };
556
+ /** How the View is currently displayed */
557
+ displayMode?: "inline" | "fullscreen" | "pip";
558
+ /** Display modes the host supports */
559
+ availableDisplayModes?: string[];
560
+ /** Container dimensions for the iframe. Specify either width or maxWidth, and either height or maxHeight. */
561
+ containerDimensions?: (
562
+ | { height: number } // If specified, container is fixed at this height
563
+ | { maxHeight?: number } // Otherwise, container height is determined by the View's height, up to this maximum height (if defined)
564
+ ) & (
565
+ | { width: number } // If specified, container is fixed at this width
566
+ | { maxWidth?: number } // Otherwise, container width is determined by the View's width, up to this maximum width (if defined)
567
+ );
568
+ /** User's language/region preference (BCP 47, e.g., "en-US") */
569
+ locale?: string;
570
+ /** User's timezone (IANA, e.g., "America/New_York") */
571
+ timeZone?: string;
572
+ /** Host application identifier */
573
+ userAgent?: string;
574
+ /** Platform type for responsive design */
575
+ platform?: "web" | "desktop" | "mobile";
576
+ /** Device capabilities such as touch */
577
+ deviceCapabilities?: {
578
+ touch?: boolean;
579
+ hover?: boolean;
580
+ }
581
+ /** Safe area boundaries in pixels */
582
+ safeAreaInsets?: {
583
+ top: number;
584
+ right: number;
585
+ bottom: number;
586
+ left: number;
587
+ };
588
+ }
589
+ ```
590
+
591
+ Example:
592
+
593
+ ```json
594
+ // Host responds with McpUiInitializeResult
595
+ {
596
+ "jsonrpc": "2.0",
597
+ "id": 1,
598
+ "result": {
599
+ "protocolVersion": "2026-01-26",
600
+ "hostCapabilities": { /* ... */ },
601
+ "hostInfo": { "name": "claude-desktop", "version": "1.0.0" },
602
+ "hostContext": {
603
+ "theme": "dark",
604
+ "styles": {
605
+ "variables": {
606
+ "--color-background-primary": "light-dark(#ffffff, #171717)",
607
+ "--color-text-primary": "light-dark(#171717, #fafafa)",
608
+ "--font-sans": "Anthropic Sans, sans-serif",
609
+ ...
610
+ },
611
+ "css": {
612
+ "fonts": "@font-face { font-family: \"Custom Font Name\"; src: url(\"https://...\"); }"
613
+ }
614
+ },
615
+ "displayMode": "inline",
616
+ "containerDimensions": { "width": 400, "maxHeight": 600 }
617
+ }
618
+ }
619
+ }
620
+ ```
621
+
622
+ ### Host Capabilities
623
+
624
+ `HostCapabilities` are sent to the View as part of the response to `ui/initialize` (inside `McpUiInitializeResult`).
625
+ They describe the features and capabilities that the Host supports.
626
+
627
+ ```typescript
628
+ interface HostCapabilities {
629
+ /** Experimental features (structure TBD). */
630
+ experimental?: {};
631
+ /** Host supports opening external URLs. */
632
+ openLinks?: {};
633
+ /** Host can proxy tool calls to the MCP server. */
634
+ serverTools?: {
635
+ /** Host supports tools/list_changed notifications. */
636
+ listChanged?: boolean;
637
+ };
638
+ /** Host can proxy resource reads to the MCP server. */
639
+ serverResources?: {
640
+ /** Host supports resources/list_changed notifications. */
641
+ listChanged?: boolean;
642
+ };
643
+ /** Host accepts log messages. */
644
+ logging?: {};
645
+ /** Sandbox configuration applied by the host. */
646
+ sandbox?: {
647
+ /** Permissions granted by the host (camera, microphone, geolocation, clipboard-write). */
648
+ permissions?: {
649
+ camera?: {};
650
+ microphone?: {};
651
+ geolocation?: {};
652
+ clipboardWrite?: {};
653
+ };
654
+ /** CSP domains approved by the host. */
655
+ csp?: {
656
+ /** Approved origins for network requests (fetch/XHR/WebSocket). */
657
+ connectDomains?: string[];
658
+ /** Approved origins for static resources (scripts, images, styles, fonts). */
659
+ resourceDomains?: string[];
660
+ /** Approved origins for nested iframes (frame-src directive). */
661
+ frameDomains?: string[];
662
+ /** Approved base URIs for the document (base-uri directive). */
663
+ baseUriDomains?: string[];
664
+ };
665
+ };
666
+ }
667
+ ```
668
+
669
+ ### Container Dimensions
670
+
671
+ The `HostContext` provides sizing information via `containerDimensions`:
672
+
673
+ - **`containerDimensions`**: The dimensions of the container that holds the View. This controls the actual space the View occupies within the host. Each dimension (height and width) operates independently and can be either **fixed** or **flexible**.
674
+
675
+ #### Dimension Modes
676
+
677
+ | Mode | Dimensions Field | Meaning |
678
+ |------|-----------------|---------|
679
+ | Fixed | `height` or `width` | Host controls the size. View should fill the available space. |
680
+ | Flexible | `maxHeight` or `maxWidth` | View controls the size, up to the specified maximum. |
681
+ | Unbounded | Field omitted | View controls the size with no limit. |
682
+
683
+ These modes can be combined independently. For example, a host might specify a fixed width but flexible height, allowing the View to grow vertically based on content.
684
+
685
+ #### View Behavior
686
+
687
+ Views should check the containerDimensions configuration and apply appropriate CSS:
688
+
689
+ ```typescript
690
+ // In the View's initialization
691
+ const containerDimensions = hostContext.containerDimensions;
692
+
693
+ if (containerDimensions) {
694
+ // Handle height
695
+ if ("height" in containerDimensions) {
696
+ // Fixed height: fill the container
697
+ document.documentElement.style.height = "100vh";
698
+ } else if ("maxHeight" in containerDimensions && containerDimensions.maxHeight) {
699
+ // Flexible with max: let content determine size, up to max
700
+ document.documentElement.style.maxHeight = `${containerDimensions.maxHeight}px`;
701
+ }
702
+ // If neither, height is unbounded
703
+
704
+ // Handle width
705
+ if ("width" in containerDimensions) {
706
+ // Fixed width: fill the container
707
+ document.documentElement.style.width = "100vw";
708
+ } else if ("maxWidth" in containerDimensions && containerDimensions.maxWidth) {
709
+ // Flexible with max: let content determine size, up to max
710
+ document.documentElement.style.maxWidth = `${containerDimensions.maxWidth}px`;
711
+ }
712
+ // If neither, width is unbounded
713
+ }
714
+ ```
715
+
716
+ #### Host Behavior
717
+
718
+ When using flexible dimensions (no fixed `height` or `width`), hosts MUST listen for `ui/notifications/size-changed` notifications from the View and update the iframe dimensions accordingly:
719
+
720
+ ```typescript
721
+ // Host listens for size changes from the View
722
+ bridge.onsizechange = ({ width, height }) => {
723
+ // Update iframe to match View's content size
724
+ if (width != null) {
725
+ iframe.style.width = `${width}px`;
726
+ }
727
+ if (height != null) {
728
+ iframe.style.height = `${height}px`;
729
+ }
730
+ };
731
+ ```
732
+
733
+ Views using the SDK automatically send size-changed notifications via ResizeObserver when `autoResize` is enabled (the default). The notifications are debounced and only sent when dimensions actually change.
734
+
735
+ ### Display Modes
736
+
737
+ Views can be displayed in different modes depending on the host's capabilities and the view's declared support.
738
+
739
+ ```typescript
740
+ type McpUiDisplayMode = "inline" | "fullscreen" | "pip";
741
+ ```
742
+
743
+ - **inline**: Default mode, embedded within the host's content flow
744
+ - **fullscreen**: View takes over the full screen/window
745
+ - **pip**: Picture-in-picture, floating overlay
746
+
747
+ #### Declaring Support
748
+
749
+ **View (`appCapabilities.availableDisplayModes`):**
750
+
751
+ Views declare which display modes they support in the `ui/initialize` request via `appCapabilities.availableDisplayModes`. This allows hosts to only offer display mode options that the view can handle.
752
+
753
+ ```typescript
754
+ // Example: View declares support for inline and fullscreen
755
+ {
756
+ method: "ui/initialize",
757
+ params: {
758
+ appCapabilities: {
759
+ availableDisplayModes: ["inline", "fullscreen"]
760
+ },
761
+ // ...
762
+ }
763
+ }
764
+ ```
765
+
766
+ **Host (`HostContext.availableDisplayModes`):**
767
+
768
+ Hosts declare which display modes they support in `HostContext.availableDisplayModes`. Views should check this before requesting a mode change.
769
+
770
+ #### Requesting Changes
771
+
772
+ Views request display mode changes via `ui/request-display-mode`. See the Requests section for message format.
773
+
774
+ #### Notifying Changes
775
+
776
+ Hosts notify views of display mode changes via `ui/notifications/host-context-changed` with the `displayMode` field.
777
+
778
+ #### Requirements
779
+
780
+ **View behavior:**
781
+ - View MUST declare all display modes it supports in `appCapabilities.availableDisplayModes` during initialization.
782
+ - View MUST check if the requested mode is in `availableDisplayModes` from host context before requesting a mode change.
783
+ - View MUST handle the response mode differing from the requested mode.
784
+
785
+ **Host behavior:**
786
+ - Host MUST NOT switch the View to a display mode that does not appear in its `appCapabilities.availableDisplayModes`, if set.
787
+ - Host MUST return the resulting mode (whether updated or not) in the response to `ui/request-display-mode`.
788
+ - If the requested mode is not available, Host SHOULD return the current display mode in the response.
789
+ - Host MAY decline display mode requests from Views that did not declare said modes in their capabilities.
790
+
791
+ ### Theming
792
+
793
+ Hosts can optionally pass CSS custom properties via `HostContext.styles.variables` for visual cohesion with the host environment.
794
+
795
+ #### Current Standardized Variables
796
+
797
+ ```typescript
798
+ /** CSS variable keys available to Views for theming. */
799
+ type McpUiStyleVariableKey =
800
+ // Background colors
801
+ | "--color-background-primary"
802
+ | "--color-background-secondary"
803
+ | "--color-background-tertiary"
804
+ | "--color-background-inverse"
805
+ | "--color-background-ghost"
806
+ | "--color-background-info"
807
+ | "--color-background-danger"
808
+ | "--color-background-success"
809
+ | "--color-background-warning"
810
+ | "--color-background-disabled"
811
+ // Text colors
812
+ | "--color-text-primary"
813
+ | "--color-text-secondary"
814
+ | "--color-text-tertiary"
815
+ | "--color-text-inverse"
816
+ | "--color-text-info"
817
+ | "--color-text-danger"
818
+ | "--color-text-success"
819
+ | "--color-text-warning"
820
+ | "--color-text-disabled"
821
+ | "--color-text-ghost"
822
+ // Border colors
823
+ | "--color-border-primary"
824
+ | "--color-border-secondary"
825
+ | "--color-border-tertiary"
826
+ | "--color-border-inverse"
827
+ | "--color-border-ghost"
828
+ | "--color-border-info"
829
+ | "--color-border-danger"
830
+ | "--color-border-success"
831
+ | "--color-border-warning"
832
+ | "--color-border-disabled"
833
+ // Ring colors
834
+ | "--color-ring-primary"
835
+ | "--color-ring-secondary"
836
+ | "--color-ring-inverse"
837
+ | "--color-ring-info"
838
+ | "--color-ring-danger"
839
+ | "--color-ring-success"
840
+ | "--color-ring-warning"
841
+ // Typography - Family
842
+ | "--font-sans"
843
+ | "--font-mono"
844
+ // Typography - Weight
845
+ | "--font-weight-normal"
846
+ | "--font-weight-medium"
847
+ | "--font-weight-semibold"
848
+ | "--font-weight-bold"
849
+ // Typography - Text Size
850
+ | "--font-text-xs-size"
851
+ | "--font-text-sm-size"
852
+ | "--font-text-md-size"
853
+ | "--font-text-lg-size"
854
+ // Typography - Heading Size
855
+ | "--font-heading-xs-size"
856
+ | "--font-heading-sm-size"
857
+ | "--font-heading-md-size"
858
+ | "--font-heading-lg-size"
859
+ | "--font-heading-xl-size"
860
+ | "--font-heading-2xl-size"
861
+ | "--font-heading-3xl-size"
862
+ // Typography - Text Line Height
863
+ | "--font-text-xs-line-height"
864
+ | "--font-text-sm-line-height"
865
+ | "--font-text-md-line-height"
866
+ | "--font-text-lg-line-height"
867
+ // Typography - Heading Line Height
868
+ | "--font-heading-xs-line-height"
869
+ | "--font-heading-sm-line-height"
870
+ | "--font-heading-md-line-height"
871
+ | "--font-heading-lg-line-height"
872
+ | "--font-heading-xl-line-height"
873
+ | "--font-heading-2xl-line-height"
874
+ | "--font-heading-3xl-line-height"
875
+ // Border radius
876
+ | "--border-radius-xs"
877
+ | "--border-radius-sm"
878
+ | "--border-radius-md"
879
+ | "--border-radius-lg"
880
+ | "--border-radius-xl"
881
+ | "--border-radius-full"
882
+ // Border width
883
+ | "--border-width-regular"
884
+ // Shadows
885
+ | "--shadow-hairline"
886
+ | "--shadow-sm"
887
+ | "--shadow-md"
888
+ | "--shadow-lg";
889
+ ```
890
+
891
+ #### Host Behavior
892
+
893
+ - Hosts can provide any subset of standardized variables, or not pass `styles` at all
894
+ - However, unexpected clashes may occur if hosts pass some color variables but not others for example, since Views are instructed to fallback on their own default values for unspecified style variables
895
+ - Hosts should use the CSS `light-dark()` function for theme-aware values (i.e. light mode and dark mode colors)
896
+
897
+ #### View Behavior
898
+
899
+ - Views should set default fallback values for the set of these variables that they use, to account for hosts who don't pass some or all style variables. This ensures graceful degradation when hosts omit `styles` or specific variables:
900
+ ```
901
+ :root {
902
+ --color-text-primary: light-dark(#171717, #000000);
903
+ --border-radius-small: 8px;
904
+ ...
905
+ }
906
+ ```
907
+ - Views can use the `applyHostStyleVariables` utility (or `useHostStyleVariables` if they prefer a React hook) to easily populate the host-provided CSS variables into their style sheet
908
+ - Views can use the `applyDocumentTheme` utility (or `useDocumentTheme` if they prefer a React hook) to easily respond to Host Context `theme` changes in a way that is compatible with the host's light/dark color variables
909
+
910
+ Example usage of standardized CSS variables:
911
+
912
+ ```css
913
+ .container {
914
+ background: var(--color-background-primary);
915
+ color: var(--color-text-primary);
916
+ font-family: var(--font-sans);
917
+ }
918
+ ```
919
+
920
+ #### Custom Fonts
921
+
922
+ Hosts can provide custom fonts via `styles.css.fonts`, which can contain `@font-face` rules for self-hosted fonts, `@import` statements for font services like Google Fonts, or both:
923
+
924
+ ```typescript
925
+ hostContext.styles.variables["--font-sans"] = '"Font Name", sans-serif';
926
+
927
+ // Self-hosted fonts
928
+ hostContext.styles.css.fonts = `
929
+ @font-face {
930
+ font-family: "Font Name";
931
+ src: url("https://url-where-font-is-hosted.com/.../Regular.otf") format("opentype");
932
+ font-weight: 400;
933
+ font-style: normal;
934
+ font-display: swap;
935
+ }
936
+ @font-face {
937
+ font-family: "Font Name";
938
+ src: url("https://url-where-font-is-hosted.com/.../Medium.otf") format("opentype");
939
+ font-weight: 500;
940
+ font-style: medium;
941
+ font-display: swap;
942
+ }
943
+ `;
944
+
945
+ // Google Fonts
946
+ hostContext.styles.css.fonts = `
947
+ @import url('https://fonts.googleapis.com/css2?family=Font+Name&display=swap');
948
+ `;
949
+ ```
950
+
951
+ Views can use the `applyHostFonts` utility to inject the font CSS into the document:
952
+
953
+ ```typescript
954
+ if (hostContext.styles?.css?.fonts) {
955
+ applyHostFonts(hostContext.styles.css.fonts);
956
+ }
957
+ ```
958
+
959
+ ### MCP Apps Specific Messages
960
+
961
+ MCP Apps introduces additional JSON-RPC methods for UI-specific functionality:
962
+
963
+ #### Requests (View → Host)
964
+
965
+ `ui/open-link` - Request host to open external URL
966
+
967
+ ```typescript
968
+ // Request
969
+ {
970
+ jsonrpc: "2.0",
971
+ id: 1,
972
+ method: "ui/open-link",
973
+ params: {
974
+ url: string // URL to open in host's browser
975
+ }
976
+ }
977
+
978
+ // Success Response
979
+ {
980
+ jsonrpc: "2.0",
981
+ id: 1,
982
+ result: {} // Empty result on success
983
+ }
984
+
985
+ // Error Response (if denied or failed)
986
+ {
987
+ jsonrpc: "2.0",
988
+ id: 1,
989
+ error: {
990
+ code: -32000, // Implementation-defined error
991
+ message: "Link opening denied by user" | "Invalid URL" | "Policy violation"
992
+ }
993
+ }
994
+ ```
995
+
996
+ Host SHOULD open the URL in the user's default browser or a new tab.
997
+
998
+ `ui/message` - Send message content to the host's chat interface
999
+
1000
+ ```typescript
1001
+ // Request
1002
+ {
1003
+ jsonrpc: "2.0",
1004
+ id: 2,
1005
+ method: "ui/message",
1006
+ params: {
1007
+ role: "user",
1008
+ content: {
1009
+ type: "text",
1010
+ text: string
1011
+ }
1012
+ }
1013
+ }
1014
+
1015
+ // Success Response
1016
+ {
1017
+ jsonrpc: "2.0",
1018
+ id: 2,
1019
+ result: {} // Empty result on success
1020
+ }
1021
+
1022
+ // Error Response (if denied or failed)
1023
+ {
1024
+ jsonrpc: "2.0",
1025
+ id: 2,
1026
+ error: {
1027
+ code: -32000, // Implementation-defined error
1028
+ message: "Message sending denied" | "Invalid message format"
1029
+ }
1030
+ }
1031
+ ```
1032
+ Host behavior:
1033
+ * Host SHOULD add the message to the conversation context, preserving the specified role.
1034
+ * Host MAY request user consent.
1035
+
1036
+ `ui/request-display-mode` - Request host to change display mode
1037
+
1038
+ ```typescript
1039
+ // Request
1040
+ {
1041
+ jsonrpc: "2.0",
1042
+ id: 3,
1043
+ method: "ui/request-display-mode",
1044
+ params: {
1045
+ mode: "inline" | "fullscreen" | "pip" // Requested display mode
1046
+ }
1047
+ }
1048
+
1049
+ // Success Response
1050
+ {
1051
+ jsonrpc: "2.0",
1052
+ id: 3,
1053
+ result: {
1054
+ mode: "inline" | "fullscreen" | "pip" // Actual display mode set
1055
+ }
1056
+ }
1057
+ ```
1058
+
1059
+ See the Display Modes section for detailed behavior requirements.
1060
+
1061
+ `ui/update-model-context` - Update the model context
1062
+
1063
+ ```typescript
1064
+ // Request
1065
+ {
1066
+ jsonrpc: "2.0",
1067
+ id: 3,
1068
+ method: "ui/update-model-context",
1069
+ params: {
1070
+ content?: ContentBlock[],
1071
+ structuredContent?: Record<string, unknown>
1072
+ }
1073
+ }
1074
+
1075
+ // Success Response
1076
+ {
1077
+ jsonrpc: "2.0",
1078
+ id: 3,
1079
+ result: {} // Empty result on success
1080
+ }
1081
+
1082
+ // Error Response (if denied or failed)
1083
+ {
1084
+ jsonrpc: "2.0",
1085
+ id: 3,
1086
+ error: {
1087
+ code: -32000, // Implementation-defined error
1088
+ message: "Context update denied" | "Invalid content format"
1089
+ }
1090
+ }
1091
+ ```
1092
+
1093
+ The View MAY send this request to update the Host's model context. This context will be used in future turns. Each request overwrites the previous context sent by the View.
1094
+ This event serves a different use case from `notifications/message` (logging) and `ui/message` (which also trigger follow-ups).
1095
+
1096
+ Host behavior:
1097
+ - SHOULD provide the context to the model in future turns
1098
+ - MAY overwrite the previous model context with the new update
1099
+ - MAY defer sending the context to the model until the next user message (including `ui/message`)
1100
+ - MAY dedupe identical `ui/update-model-context` calls
1101
+ - If multiple updates are received before the next user message, Host SHOULD only send the last update to the model
1102
+ - MAY display context updates to the user
1103
+
1104
+ #### Notifications (Host → View)
1105
+
1106
+ `ui/notifications/tool-input` - Host MUST send this notification with the complete tool arguments after the View's initialize request completes.
1107
+
1108
+ ```typescript
1109
+ {
1110
+ jsonrpc: "2.0",
1111
+ method: "ui/notifications/tool-input",
1112
+ params: {
1113
+ arguments: Record<string, unknown> // Tool input arguments
1114
+ }
1115
+ }
1116
+ ```
1117
+
1118
+ Host sends this notification after the View's initialize request completes, when tool arguments become available. This notification is sent at most once and is required before sending `ui/notifications/tool-result`.
1119
+
1120
+ `ui/notifications/tool-input-partial` - Host MAY send this notification zero or more times while the agent is streaming tool arguments, before `ui/notifications/tool-input` is sent.
1121
+
1122
+ ```typescript
1123
+ {
1124
+ jsonrpc: "2.0",
1125
+ method: "ui/notifications/tool-input-partial",
1126
+ params: {
1127
+ arguments: Record<string, unknown> // Tool input arguments
1128
+ }
1129
+ }
1130
+ ```
1131
+
1132
+ The arguments object represents best-effort recovery of incomplete JSON, with unclosed structures automatically closed to produce valid JSON. Host behavior (optional):
1133
+
1134
+ - MAY parse the agent's partial JSON output by closing unclosed brackets/braces
1135
+ - MAY send recovered arguments as they become available during streaming
1136
+ - MUST stop sending once `ui/notifications/tool-input` is sent with complete arguments
1137
+
1138
+ View behavior (optional):
1139
+
1140
+ - MAY ignore these notifications entirely
1141
+ - MAY render progressive loading/streaming states based on available fields
1142
+ - MUST NOT rely on partial arguments for critical operations
1143
+ - SHOULD gracefully handle missing or changing fields between notifications
1144
+
1145
+ `ui/notifications/tool-result` - Tool execution result
1146
+
1147
+ ```typescript
1148
+ {
1149
+ jsonrpc: "2.0",
1150
+ method: "ui/notifications/tool-result",
1151
+ params: CallToolResult // Standard MCP type
1152
+ }
1153
+ ```
1154
+
1155
+ Host MUST send this notification when tool execution completes (if the View is displayed during tool execution).
1156
+
1157
+ `ui/notifications/tool-cancelled` - Tool execution was cancelled
1158
+
1159
+ ```typescript
1160
+ {
1161
+ jsonrpc: "2.0",
1162
+ method: "ui/notifications/tool-cancelled",
1163
+ params: {
1164
+ reason: string
1165
+ }
1166
+ }
1167
+ ```
1168
+
1169
+ Host MUST send this notification if the tool execution was cancelled, for any reason (which can optionally be specified), including user action, sampling error, classifier intervention, etc.
1170
+
1171
+ `ui/resource-teardown` - Host notifies View before teardown
1172
+
1173
+ ```typescript
1174
+ {
1175
+ jsonrpc: "2.0",
1176
+ id: 1,
1177
+ method: "ui/resource-teardown",
1178
+ params: {
1179
+ reason: string
1180
+ }
1181
+ }
1182
+
1183
+ // Success Response
1184
+ {
1185
+ jsonrpc: "2.0",
1186
+ id: 1,
1187
+ result: {} // Empty result on success
1188
+ }
1189
+
1190
+ // Error Response (if failed)
1191
+ {
1192
+ jsonrpc: "2.0",
1193
+ id: 1,
1194
+ error: {
1195
+ code: -32000, // Implementation-defined error
1196
+ message: "Teardown error"
1197
+ }
1198
+ }
1199
+ ```
1200
+
1201
+ Host MUST send this notification before tearing down the UI resource, for any reason, including user action, resource re-allocation, etc. The Host MAY specify the reason.
1202
+ Host SHOULD wait for a response before tearing down the resource (to prevent data loss).
1203
+
1204
+ `ui/notifications/size-changed` - View's size changed
1205
+
1206
+ ```typescript
1207
+ {
1208
+ jsonrpc: "2.0",
1209
+ method: "ui/notifications/size-changed",
1210
+ params: {
1211
+ width: number, // Viewport width in pixels
1212
+ height: number // Viewport height in pixels
1213
+ }
1214
+ }
1215
+ ```
1216
+
1217
+ The View SHOULD send this notification when rendered content body size changes (e.g. using ResizeObserver API to report up to date size).
1218
+
1219
+ `ui/notifications/host-context-changed` - Host context has changed
1220
+
1221
+ ```typescript
1222
+ {
1223
+ jsonrpc: "2.0",
1224
+ method: "ui/notifications/host-context-changed",
1225
+ params: Partial<HostContext> // See HostContext type above
1226
+ }
1227
+ ```
1228
+
1229
+ Host MAY send this notification when any context field changes (e.g., theme toggle, display mode change, device orientation change, window/panel resize). This notification contains partial updates - the View SHOULD merge received fields with its current context state.
1230
+
1231
+ #### Reserved Messages (Sandbox Proxy)
1232
+
1233
+ These messages are reserved for web-based hosts that implement the recommended double-iframe sandbox architecture:
1234
+
1235
+ `ui/notifications/sandbox-proxy-ready` (Sandbox Proxy → Host) - Sandbox proxy is ready
1236
+
1237
+ ```typescript
1238
+ {
1239
+ jsonrpc: "2.0",
1240
+ method: "ui/notifications/sandbox-proxy-ready",
1241
+ params: {}
1242
+ }
1243
+ ```
1244
+
1245
+ `ui/notifications/sandbox-resource-ready` (Host → Sandbox Proxy) - HTML resource ready to load
1246
+
1247
+ ```typescript
1248
+ {
1249
+ jsonrpc: "2.0",
1250
+ method: "ui/notifications/sandbox-resource-ready",
1251
+ params: {
1252
+ html: string, // HTML content to load
1253
+ sandbox?: string, // Optional override for inner iframe `sandbox` attribute
1254
+ csp?: { // CSP configuration from resource metadata
1255
+ connectDomains?: string[],
1256
+ resourceDomains?: string[],
1257
+ frameDomains?: string[],
1258
+ baseUriDomains?: string[],
1259
+ },
1260
+ permissions?: { // Sandbox permissions from resource metadata
1261
+ camera?: {},
1262
+ microphone?: {},
1263
+ geolocation?: {},
1264
+ clipboardWrite?: {},
1265
+ }
1266
+ }
1267
+ }
1268
+ ```
1269
+
1270
+ These messages facilitate the communication between the outer sandbox proxy iframe and the host, enabling secure loading of untrusted HTML content. The `permissions` field maps to the inner iframe's `allow` attribute for Permission Policy features.
1271
+
1272
+ ### Lifecycle
1273
+
1274
+ The typical lifecycle for rendering a UI resource:
1275
+
1276
+ #### 1. Connection & Discovery
1277
+
1278
+ ```mermaid
1279
+ sequenceDiagram
1280
+ participant H as Host
1281
+ participant S as MCP Server
1282
+
1283
+ autonumber
1284
+ S -->> H: resources/list (includes ui:// resources)
1285
+ S -->> H: tools/list (includes tools with _meta.ui metadata)
1286
+ ```
1287
+
1288
+ #### 2. UI Initialization (Desktop/Native Hosts)
1289
+
1290
+ ```mermaid
1291
+ sequenceDiagram
1292
+ participant H as Host
1293
+ participant UI as View (iframe)
1294
+ participant P as Sandbox Proxy
1295
+ participant S as MCP Server
1296
+
1297
+ autonumber
1298
+ par UI Tool call
1299
+ H ->> S: tools/call to Tool with _meta.ui metadata
1300
+ and UI initialization
1301
+ alt Desktop/Native hosts
1302
+ H ->> H: Render View in an iframe (HTML from the ui:// resource)
1303
+ else Web hosts
1304
+ H ->> H: Render Sandbox Proxy in an iframe (different origin)
1305
+ P ->> H: ui/notifications/sandbox-proxy-ready
1306
+ H -->> P: ui/notifications/sandbox-resource-ready (HTML content)
1307
+ P -> P: Render inner iframe with HTML
1308
+
1309
+ end
1310
+ UI ->> H: ui/initialize
1311
+ H -->> UI: McpUiInitializeResult (e.g., host-context, capabilities, etc.)
1312
+ UI ->> H: ui/notifications/initialized
1313
+ opt Stream Tool input to UI
1314
+ H -->> UI: ui/notifications/tool-input-partial (0..n)
1315
+ end
1316
+ H -->> UI: ui/notifications/tool-input (complete)
1317
+ end
1318
+ alt Tool complete
1319
+ H -->> UI: ui/notifications/tool-result
1320
+ else Tool cancelled
1321
+ H -->> UI: ui/notifications/tool-cancelled
1322
+ end
1323
+ ```
1324
+
1325
+ Note: when the View is rendered inside a sandbox, the sandbox transparently passes messages between the View and the Host, except for messages named `ui/notifications/sandbox-*`.
1326
+
1327
+ #### 3. Interactive Phase
1328
+
1329
+ ```mermaid
1330
+ sequenceDiagram
1331
+ actor U as User / Agent
1332
+ participant H as Host
1333
+ participant UI as View (iframe)
1334
+ participant S as MCP Server
1335
+ loop Interactive phase
1336
+ U ->> UI: interaction (e.g., click)
1337
+ alt Tool call
1338
+ UI ->> H: tools/call
1339
+ H ->> S: tools/call
1340
+ opt Stream Tool input to UI
1341
+ H -->> UI: ui/notifications/tool-input-partial (0..n)
1342
+ end
1343
+ H -->> UI: ui/notifications/tool-input (complete)
1344
+ H-->>UI: ui/notifications/tool-result
1345
+ else Message
1346
+ UI ->> H: ui/message
1347
+ H -->> UI: ui/message response
1348
+ H -->> H: Process message and follow up
1349
+ else Context update
1350
+ UI ->> H: ui/update-model-context
1351
+ H ->> H: Store model context (overwrite existing)
1352
+ H -->> UI: ui/update-model-context response
1353
+ else Log
1354
+ UI ->> H: notifications/message
1355
+ H ->> H: Record log for debugging/telemetry
1356
+ else Resource read
1357
+ UI ->> H: resources/read
1358
+ H ->> S: resources/read
1359
+ S --> H: resources/read response
1360
+ H --> UI: resources/read response
1361
+ end
1362
+ opt View notifications
1363
+ UI ->> H: notifications (e.g., ui/notifications/size-changed)
1364
+ end
1365
+ opt Host notifications
1366
+ H ->> UI: notifications (e.g., ui/notifications/host-context-changed)
1367
+ end
1368
+ end
1369
+ ```
1370
+
1371
+ #### 4. Cleanup
1372
+
1373
+ ```mermaid
1374
+ sequenceDiagram
1375
+ participant H as Host
1376
+ participant UI as View (iframe)
1377
+ H ->> UI: ui/resource-teardown
1378
+ UI --> UI: Graceful termination
1379
+ UI -->> H: ui/resource-teardown response
1380
+ H -x H: Tear down iframe and listeners
1381
+ ```
1382
+
1383
+ Note: Cleanup may be triggered at any point in the lifecycle following View initialization.
1384
+
1385
+ #### Key Differences from Pre-SEP MCP-UI:
1386
+
1387
+ - Handshakes using MCP-like `ui/initialize` / `ui/notifications/initialized` messages instead of `iframe-ready`
1388
+ - Capabilities negotiated via `McpUiInitializeResult`
1389
+ - Tool data passed via notifications
1390
+
1391
+ ### Data Passing
1392
+
1393
+ Tool execution results are passed to the View through two mechanisms:
1394
+
1395
+ #### 1. Tool Input (via `ui/notifications/tool-input` notification)
1396
+
1397
+ The original tool call arguments:
1398
+
1399
+ ```typescript
1400
+ // Tool was called with (JSON-RPC request from Host to Server):
1401
+ {
1402
+ jsonrpc: "2.0",
1403
+ id: 1,
1404
+ method: "tools/call",
1405
+ params: {
1406
+ name: "get_weather",
1407
+ arguments: {
1408
+ location: "San Francisco"
1409
+ }
1410
+ }
1411
+ }
1412
+
1413
+ // View receives (JSON-RPC notification from Host to View):
1414
+ {
1415
+ jsonrpc: "2.0",
1416
+ method: "ui/notifications/tool-input",
1417
+ params: {
1418
+ arguments: {
1419
+ location: "San Francisco"
1420
+ }
1421
+ }
1422
+ }
1423
+ ```
1424
+
1425
+ #### 2. Tool Result (via `ui/notifications/tool-result` notification)
1426
+
1427
+ The tool's execution result:
1428
+
1429
+ ```typescript
1430
+ // Server returns from tool execution (JSON-RPC response):
1431
+ {
1432
+ jsonrpc: "2.0",
1433
+ id: 1, // Matches the tools/call request id
1434
+ result: {
1435
+ content: [
1436
+ { type: "text", text: "Current weather: Sunny, 72°F" }
1437
+ ],
1438
+ structuredContent: {
1439
+ temperature: 72,
1440
+ conditions: "sunny",
1441
+ humidity: 45
1442
+ },
1443
+ _meta: {
1444
+ timestamp: "2025-11-10T15:30:00Z",
1445
+ source: "weather-api"
1446
+ }
1447
+ }
1448
+ }
1449
+
1450
+ // View receives (JSON-RPC notification):
1451
+ {
1452
+ jsonrpc: "2.0",
1453
+ method: "ui/notifications/tool-result",
1454
+ params: {
1455
+ content: [
1456
+ { type: "text", text: "Current weather: Sunny, 72°F" }
1457
+ ],
1458
+ structuredContent: {
1459
+ temperature: 72,
1460
+ conditions: "sunny",
1461
+ humidity: 45
1462
+ },
1463
+ _meta: {
1464
+ timestamp: "2025-11-10T15:30:00Z",
1465
+ source: "weather-api"
1466
+ }
1467
+ }
1468
+ }
1469
+ ```
1470
+
1471
+ **Best Practices:**
1472
+
1473
+ - `content`: Text representation for model context and text-only hosts
1474
+ - `structuredContent`: Structured data optimized for UI rendering (not added to model context)
1475
+ - `_meta`: Additional metadata (timestamps, version info, etc.) not intended for model context
1476
+
1477
+ #### 3. Interactive Updates
1478
+
1479
+ Views can request fresh data by calling tools:
1480
+
1481
+ ```typescript
1482
+ // View requests updated data
1483
+ await client.callTool("get_weather", { location: "New York" });
1484
+
1485
+ // Result returned via standard tools/call response
1486
+ ```
1487
+
1488
+ This pattern enables interactive, self-updating views.
1489
+
1490
+ Note: Tools with `visibility: ["app"]` are hidden from the agent but remain callable by apps via `tools/call`. This enables UI-only interactions (refresh buttons, form submissions) without exposing implementation details to the model. See the Visibility section under Resource Discovery for details.
1491
+
1492
+ ### Client\<\>Server Capability Negotiation
1493
+
1494
+ Clients and servers negotiate MCP Apps support through the standard MCP extensions capability mechanism (defined in SEP-1724).
1495
+
1496
+ #### Client (Host) Capabilities
1497
+
1498
+ Clients advertise MCP Apps support in the initialize request using the extension identifier `io.modelcontextprotocol/ui`:
1499
+
1500
+ ```json
1501
+ {
1502
+ "method": "initialize",
1503
+ "params": {
1504
+ "protocolVersion": "2024-11-05",
1505
+ "capabilities": {
1506
+ "extensions": {
1507
+ "io.modelcontextprotocol/ui": {
1508
+ "mimeTypes": ["text/html;profile=mcp-app"]
1509
+ }
1510
+ }
1511
+ },
1512
+ "clientInfo": {
1513
+ "name": "claude-desktop",
1514
+ "version": "1.0.0"
1515
+ }
1516
+ }
1517
+ }
1518
+ ```
1519
+
1520
+ **Extension Settings:**
1521
+
1522
+ - `mimeTypes`: Array of supported content types (REQUIRED, e.g., `["text/html;profile=mcp-app"]`)
1523
+
1524
+ Future versions may add additional settings:
1525
+
1526
+ - `features`: Specific feature support (e.g., `["streaming", "persistence"]`)
1527
+ - `sandboxPolicies`: Supported sandbox attribute configurations
1528
+
1529
+ #### Server Behavior
1530
+
1531
+ Servers SHOULD check client capabilities before registering UI-enabled tools. The SDK provides the `getUiCapability` helper for this:
1532
+
1533
+ ```typescript
1534
+ import { getUiCapability, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
1535
+
1536
+ const uiCap = getUiCapability(clientCapabilities);
1537
+ if (uiCap?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) {
1538
+ // Register tools with UI templates
1539
+ server.registerTool("get_weather", {
1540
+ description: "Get weather with interactive dashboard",
1541
+ inputSchema: { /* ... */ },
1542
+ _meta: {
1543
+ ui: { resourceUri: "ui://weather-server/dashboard" }
1544
+ }
1545
+ });
1546
+ } else {
1547
+ // Register text-only version
1548
+ server.registerTool("get_weather", {
1549
+ description: "Get weather as text",
1550
+ inputSchema: { /* ... */ }
1551
+ // No UI metadata
1552
+ });
1553
+ }
1554
+ ```
1555
+
1556
+ **Graceful Degradation:**
1557
+
1558
+ - Servers SHOULD provide text-only fallback behavior for all UI-enabled tools
1559
+ - Tools MUST return meaningful content array even when UI is available
1560
+ - Servers MAY register different tool variants based on host capabilities
1561
+
1562
+ ### Extensibility
1563
+
1564
+ This specification defines the Minimum Viable Product (MVP) for MCP Apps. Future extensions may include:
1565
+
1566
+ **Content Types (deferred from MVP):**
1567
+
1568
+ - `externalUrl`: Embed external web applications (e.g., `text/uri-list`)
1569
+
1570
+ **Advanced Features (see Future Considerations):**
1571
+
1572
+ - Support multiple UI resources in a tool response
1573
+ - State persistence and restoration
1574
+ - Custom sandbox policies per resource
1575
+ - View-to-View communication
1576
+ - Screenshot/preview generation APIs
1577
+
1578
+ ## Rationale
1579
+
1580
+ This proposal synthesizes feedback from the UI CWG and MCP-UI community, host implementors, and lessons from similar solutions. The guiding principle of this proposal is to start lean and expand in the future. There are breaking changes from existing solutions, which will be addressed via the MCP-UI SDK during the migration period.
1581
+
1582
+ ### Design Decisions
1583
+
1584
+ #### 1. Predeclared Resources vs. Inline Embedding
1585
+
1586
+ **Decision:** Require UI resources to be registered and referenced in tool metadata.
1587
+
1588
+ **Rationale:**
1589
+
1590
+ - Enables hosts to prefetch templates before tool execution, improving performance
1591
+ - Separates presentation (template) from data (tool results), improving caching
1592
+ - Allows hosts to review UI templates
1593
+ - Aligns with MCP's resource discovery pattern
1594
+
1595
+ **Alternatives considered:**
1596
+
1597
+ - **Embedded resources:** Current MCP-UI approach, where resources are returned in tool results. Although it's more convenient for server development, it was deferred due to the gaps in performance optimization and the challenges in the UI review process.
1598
+ - **Resource links:** Predeclare the resources but return links in tool results. Deferred due to the gaps in performance optimization.
1599
+
1600
+ #### 2. Host communication via MCP Transport
1601
+
1602
+ **Decision:** Use MCP's JSON-RPC base protocol over postMessage instead of custom message format.
1603
+
1604
+ **Rationale:**
1605
+
1606
+ - Reuses existing MCP infrastructure (type definitions, error handling, timeouts)
1607
+ - UI developers can use standard MCP SDK (`@modelcontextprotocol/sdk`) or alternatives
1608
+ - Automatic compatibility with future MCP features (long-running tools, sampling, etc.)
1609
+ - Better auditability through structured JSON-RPC messages
1610
+ - Reduces maintenance burden (no parallel protocol to evolve)
1611
+
1612
+ **Alternatives considered:**
1613
+
1614
+ - **Custom message protocol:** Current MCP-UI approach with message types like tool, prompt, etc. These message types can be translated to a subset of the proposed JSON-RPC messages.
1615
+ - **Global API object:** Rejected because it requires host-specific injection and doesn't work with external iframe sources. Syntactic sugar may still be added on the server/UI side.
1616
+
1617
+ #### 3. Support Raw HTML Content Type
1618
+
1619
+ **Decision:** MVP supports only `text/html;profile=mcp-app` (rawHtml), with other types explicitly deferred.
1620
+
1621
+ **Rationale:**
1622
+
1623
+ - HTML is universally supported and well-understood
1624
+ - Simplest security model (standard iframe sandbox)
1625
+ - Allows screenshot/preview generation (e.g., via html2canvas)
1626
+ - Sufficient for most observed use cases
1627
+ - Provides clear baseline for future extensions
1628
+
1629
+ **Alternatives considered:**
1630
+
1631
+ - **Include external URLs in MVP:** This is one of the easiest content types for servers to adopt, as it's possible to embed regular apps. However, it was deferred due to concerns around model visibility, inability to screenshot content, and review process.
1632
+ - **Support multiple content types:** Deferred to maintain a lean MVP.
1633
+
1634
+ #### 4. Host Theming via CSS Variables
1635
+
1636
+ **Decision:** Provide a standardized set of CSS custom properties for visual cohesion.
1637
+
1638
+ **Rationale:**
1639
+
1640
+ - CSS variables are universal, framework-agnostic, and require no runtime
1641
+ - Views apply styles via `var(--name)` with fallbacks for graceful degradation
1642
+ - Limited variable set (colors, typography, borders) ensures hosts can realistically provide all values
1643
+ - Spacing intentionally excluded—layouts break when spacing varies from original design
1644
+ - No UI component library—no single library works across all host environments
1645
+
1646
+ **Alternatives considered:**
1647
+
1648
+ - **Full design system:** Rejected as too prescriptive; hosts have different aesthetics
1649
+ - **Inline styles in tool results:** Rejected; separating theming from data enables caching and updates
1650
+ - **CSS-in-JS injection:** Rejected; framework-specific and security concerns with injected code
1651
+
1652
+ #### 5. Tool Visibility via Metadata
1653
+
1654
+ **Decision:** Use `_meta.ui.visibility` array to control tool accessibility between model and app.
1655
+
1656
+ **Rationale:**
1657
+
1658
+ - Nested `_meta.ui` structure groups all UI-related metadata cleanly
1659
+ - Array format (`["model", "app"]`) allows flexible combinations
1660
+ - Default `["model", "app"]` allows both agent and app to access tools
1661
+ - `"app"` scope is per-server, preventing cross-server tool calls
1662
+ - Cleaner than OpenAI's two-field approach (`widgetAccessible` + `visibility`)
1663
+
1664
+ **Alternatives considered:**
1665
+
1666
+ - **Two separate fields:** OpenAI uses `widgetAccessible` and `visibility` separately. Rejected as redundant; single `visibility` array covers all cases.
1667
+ - **Boolean `private` flag:** Simpler but less flexible; doesn't express model-only tools.
1668
+ - **Flat `ui/visibility` key:** Rejected in favor of nested structure for consistency with future `_meta.ui` fields.
1669
+
1670
+ ### Backward Compatibility
1671
+
1672
+ The proposal builds on the existing core protocol. There are no incompatibilities.
1673
+
1674
+ ### Reference Implementation
1675
+
1676
+ The MCP-UI project serves as a reference implementation demonstrating the core concept, though it uses pre-SEP patterns.
1677
+
1678
+ Olivier Chafik has developed a prototype demonstrating the pattern described in this SEP.
1679
+
1680
+ ## Security Implications
1681
+
1682
+ Hosting interactive UI content from potentially untrusted MCP servers requires careful security consideration.
1683
+
1684
+ ### Threat Model
1685
+
1686
+ Attackers may use the embedded UI in different scenarios. For example:
1687
+
1688
+ - Malicious server delivers harmful HTML content
1689
+ - Compromised View attempts to escape sandbox
1690
+ - View attempts unauthorized tool execution
1691
+ - View exfiltrates sensitive host data
1692
+ - View performs phishing or social engineering
1693
+
1694
+ ### Mitigations
1695
+
1696
+ #### 1. Iframe Sandboxing
1697
+
1698
+ All View content MUST be rendered in sandboxed iframes with restricted permissions.
1699
+
1700
+ The sandbox limits the View from accessing the host or manipulating it. All communication with the host is done via `postMessage`, where the host is in control.
1701
+
1702
+ #### 2. Auditable Communication
1703
+
1704
+ All View-to-host communication goes through auditable MCP JSON-RPC messages.
1705
+
1706
+ **Host behavior:**
1707
+
1708
+ - Validate all incoming messages from UI iframes
1709
+ - Reject malformed message types
1710
+ - Log View-initiated RPC calls for security review
1711
+
1712
+ #### 3. Predeclared Resource Review
1713
+
1714
+ Hosts receive UI templates during connection setup, before tool execution.
1715
+
1716
+ **Host behavior:**
1717
+
1718
+ - Review HTML content for obvious malicious patterns
1719
+ - Generate hash/signature for resources
1720
+ - Warn users about suspicious content
1721
+ - Implement allowlists/blocklists based on resource hashes
1722
+
1723
+ #### 4. Content Security Policy Enforcement
1724
+
1725
+ Hosts MUST enforce Content Security Policies based on resource metadata.
1726
+
1727
+ **CSP Construction from Metadata:**
1728
+
1729
+ ```typescript
1730
+ const csp = resource._meta?.ui?.csp; // `resource` is extracted from the `contents` of the `resources/read` result
1731
+ const permissions = resource._meta?.ui?.permissions;
1732
+
1733
+ const cspValue = `
1734
+ default-src 'none';
1735
+ script-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
1736
+ style-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
1737
+ connect-src 'self' ${csp?.connectDomains?.join(' ') || ''};
1738
+ img-src 'self' data: ${csp?.resourceDomains?.join(' ') || ''};
1739
+ font-src 'self' ${csp?.resourceDomains?.join(' ') || ''};
1740
+ media-src 'self' data: ${csp?.resourceDomains?.join(' ') || ''};
1741
+ frame-src ${csp?.frameDomains?.join(' ') || "'none'"};
1742
+ object-src 'none';
1743
+ base-uri ${csp?.baseUriDomains?.join(' ') || "'self'"};
1744
+ `;
1745
+
1746
+ // Permission Policy for iframe allow attribute
1747
+ const allowList: string[] = [];
1748
+ if (permissions?.camera) allowList.push('camera');
1749
+ if (permissions?.microphone) allowList.push('microphone');
1750
+ if (permissions?.geolocation) allowList.push('geolocation');
1751
+ const allowAttribute = allowList.join(' ');
1752
+ ```
1753
+
1754
+ **Security Requirements:**
1755
+
1756
+ - Host MUST block connections to undeclared domains
1757
+ - Host SHOULD warn users when UI requires external domain access
1758
+ - Host MAY implement global domain allowlists/blocklists
1759
+
1760
+ ### Other risks
1761
+
1762
+ - **Social engineering:** UI can still display misleading content. Hosts should clearly indicate sandboxed UI boundaries.
1763
+ - **Resource consumption:** Malicious View can consume CPU/memory. Hosts should implement resource limits.
1764
+
1765
+ ## Reservations in MCP
1766
+
1767
+ - The resource prefix `ui://` will be reserved for MCP Apps
1768
+ - The label `io.modelcontextprotocol/ui` is reserved