Skip to content

Commit d58ed85

Browse files
docs: frameDomains and baseUriDomains for mcp apps (#6684)
1 parent b5e8ced commit d58ed85

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

documentation/docs/tutorials/building-mcp-apps.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
169169
csp: {
170170
connectDomains: [],
171171
resourceDomains: [],
172+
frameDomains: [],
173+
baseUriDomains: [],
172174
},
173175
prefersBorder: true,
174176
},
@@ -532,6 +534,60 @@ Try:
532534
533535
Your server returns a `ui://` resource URI, goose fetches the HTML and renders it in an iframe. The app communicates back via `postMessage`—requesting theme info, sending messages to chat, or resizing itself.
534536
535-
MCP Apps run sandboxed with CSP restrictions. See the [MCP Apps Specification](https://github.com/modelcontextprotocol/ext-apps) for details on security and the full protocol.
537+
MCP Apps run in a sandboxed iframe with strict Content Security Policy restrictions.
538+
539+
### Content Security Policy Configuration
540+
541+
By default, apps can only load resources from their own origin. If your app needs to interact with external domains—such as loading resources from a CDN, making API calls, or embedding maps—you can configure which domains are allowed through the `csp` object in the resource's `_meta.ui` section.
542+
543+
```javascript
544+
_meta: {
545+
ui: {
546+
csp: {
547+
connectDomains: [], // Domains for fetch/XHR requests
548+
resourceDomains: [], // Domains for scripts, styles, images, fonts, media
549+
frameDomains: [], // Origins allowed for nested iframes
550+
baseUriDomains: [], // Additional allowed base URIs
551+
},
552+
},
553+
}
554+
```
555+
556+
| Option | CSP Directive | Purpose | Default |
557+
|--------|---------------|---------|---------|
558+
| `connectDomains` | `connect-src` | Domains your app can make network requests to | Same-origin only |
559+
| `resourceDomains` | `script-src`, `style-src`, `img-src`, `font-src`, `media-src` | Domains for loading external resources | Same-origin only |
560+
| `frameDomains` | `frame-src` | Origins allowed for nested `<iframe>` elements | `'none'` (no iframes) |
561+
| `baseUriDomains` | `base-uri` | Additional domains allowed for `<base>` element | `'self'` only |
562+
563+
<details>
564+
<summary>Examples</summary>
565+
566+
**Embedding a map:**
567+
568+
```javascript
569+
csp: {
570+
frameDomains: ['https://www.openstreetmap.org'],
571+
resourceDomains: ['https://tile.openstreetmap.org'],
572+
}
573+
```
574+
575+
**Loading resources from a CDN:**
576+
577+
```javascript
578+
csp: {
579+
resourceDomains: ['https://cdn.jsdelivr.net', 'https://unpkg.com'],
580+
connectDomains: ['https://api.example.com'],
581+
}
582+
```
583+
584+
</details>
585+
586+
See the [MCP Apps Specification](https://github.com/modelcontextprotocol/ext-apps) for details on security and the full protocol.
587+
588+
:::warning Security Consideration
589+
Only add domains you trust. Each domain you add expands what external content can be loaded or embedded in your app. Keep the list minimal and specific to reduce security risks.
590+
:::
591+
536592

537593

0 commit comments

Comments
 (0)