document.modelContext. Items from the iframe are namespaced with the element’s id to prevent collisions.
Installation
@mcp-b/global (or any document.modelContext implementation) installed.
Minimal example
Usage
@mcp-b/mcp-iframe auto-registers the <mcp-iframe> custom element. No additional setup is required.
Attributes
Standard iframe attributes (
sandbox, allow, width, height, loading, referrerpolicy, name, srcdoc, allowfullscreen, credentialless) are mirrored to the internal <iframe> element.
Events
All
tools, resources, and prompts arrays contain the prefixed names as registered on the parent.
Name prefixing
Tools and prompts from the iframe are registered on the parent as{id}{separator}{name}:
Prefixed names must match the MCP name pattern
^[a-zA-Z0-9_-]{1,128}$. Names that exceed 128 characters or contain invalid characters are skipped with a console error.
Resource URIs are prefixed the same way: a resource config://settings in an iframe with id="my-app" becomes my-app_config://settings on the parent.
Properties
Methods
Programmatic registration
To register the custom element with a different tag name:@mcp-b/mcp-iframe without calling registerMCPIframeElement, the element is auto-registered as <mcp-iframe> in browser environments.
Lifecycle
- On
connectedCallback, the element creates an internal<iframe>and mirrors attributes. - When the iframe fires its
loadevent, the element creates anIframeParentTransportand an MCPClient, then connects. - On successful connection, tools, resources, and prompts are fetched from the iframe’s MCP server.
- Each item is registered on the parent’s
document.modelContextwith the element’s prefix. - The
mcp-iframe-readyevent fires. - On
disconnectedCallback, all registered items are unregistered and the client and transport are closed.
src, srcdoc, target-origin, or channel while connected triggers a reconnection cycle.
Related
- Bridge tools across iframes for a step-by-step guide
- @mcp-b/transports for the underlying
IframeParentTransportandIframeChildTransport - Transports and bridges for the architectural context
