You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> For a full example that implements this pattern, see: [`examples/video-resource-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/video-resource-server).
298
298
299
+
## Configuring CSP and CORS
300
+
301
+
Unlike regular web apps, MCP Apps HTML is served as an MCP resource and runs in a sandboxed iframe with no same-origin server. Any app that makes network requests must configure Content Security Policy (CSP) and possibly CORS.
302
+
303
+
**CSP** controls what the _browser_ allows. You must declare _all_ origins in {@link types!McpUiResourceMeta.csp `_meta.ui.csp`} ({@link types!McpUiResourceCsp `McpUiResourceCsp`}) — including `localhost` during development. Declare `connectDomains` for fetch/XHR/WebSocket requests and `resourceDomains` for scripts, stylesheets, images, and fonts.
304
+
305
+
**CORS** controls what the _API server_ allows. Public APIs that respond with `Access-Control-Allow-Origin: *` or use API key authentication work without CORS configuration. For APIs that allowlist specific origins, use {@link types!McpUiResourceMeta.domain `_meta.ui.domain`} to give the app a stable origin that the API server can allowlist. The format is host-specific, so check each host's documentation for its supported format.
description: "Internal dashboard with company data",
327
+
},
328
+
async () => ({
329
+
contents: [
330
+
{
331
+
uri: "ui://dashboard/view.html",
332
+
mimeType: RESOURCE_MIME_TYPE,
333
+
text: dashboardHtml,
334
+
_meta: {
335
+
ui: {
336
+
// CSP: tell browser the app is allowed to make requests
337
+
csp: {
338
+
connectDomains: ["https://api.example.com"],
339
+
},
340
+
// CORS: give app a stable origin for the API server to allowlist
341
+
//
342
+
// (Public APIs that use `Access-Control-Allow-Origin: *` or API
343
+
// key auth don't need this.)
344
+
domain: APP_DOMAIN,
345
+
},
346
+
},
347
+
},
348
+
],
349
+
}),
350
+
);
351
+
```
352
+
353
+
Note that `_meta.ui.csp` and `_meta.ui.domain` are set in the `contents[]` objects returned by the resource read callback, not in `registerAppResource()`'s config object.
354
+
355
+
> [!NOTE]
356
+
> For full examples that configures CSP, see: [`examples/sheet-music-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/sheet-music-server) (`connectDomains`) and [`examples/map-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/map-server) (`connectDomains` and `resourceDomains`).
357
+
299
358
## Adapting to host context (theme, styling, fonts, and safe areas)
300
359
301
360
The host provides context about its environment via {@link types!McpUiHostContext `McpUiHostContext`}. Use this to adapt your app's appearance and layout:
0 commit comments