<mcp-iframe> custom element wraps an iframe and automatically exposes its tools, resources, and prompts to the parent page’s navigator.modelContext.
Installation
Quick Start
Parent page — import to auto-register the element:Item Prefixing
Items are exposed with the element’sid as prefix to prevent naming conflicts:
| Child registers | Parent sees |
|---|---|
calculate | my-app:calculate |
config://settings | my-app:config://settings |
Attributes
Standard iframe attributes (src, width, height, sandbox, etc.) are mirrored to the internal iframe.
MCP-Specific Attributes
| Attribute | Default | Description |
|---|---|---|
target-origin | Auto-detected | Origin for postMessage security |
channel | 'mcp-iframe' | Channel identifier |
call-timeout | 30000 | Tool call timeout (ms) |
prefix-separator | ':' | Separator between prefix and name |
Events
| Event | Detail | Description |
|---|---|---|
mcp-iframe-ready | { tools, resources, prompts } | Connection established |
mcp-iframe-error | { error } | Connection failed |
mcp-iframe-tools-changed | { tools, resources, prompts } | Items refreshed |
Properties & Methods
| Property | Type | Description |
|---|---|---|
ready | boolean | Connection status |
iframe | HTMLIFrameElement | The wrapped iframe |
exposedTools | string[] | Prefixed tool names |
exposedResources | string[] | Prefixed resource URIs |
exposedPrompts | string[] | Prefixed prompt names |
itemPrefix | string | Current prefix (e.g., my-app:) |
| Method | Description |
|---|---|
refresh() | Re-fetch items from iframe |
Multiple Iframes
Each iframe uses itsid as prefix:
calc:add, calc:multiply, todos:create, todos:list, etc.
Cross-Origin
For cross-origin iframes, settarget-origin explicitly:
