Skip to main content
A Web Component that wraps an iframe and bridges its MCP tools, resources, and prompts to the parent page’s document.modelContext. Items from the iframe are namespaced with the element’s id to prevent collisions.

Installation

The iframe page must have @mcp-b/global (or any document.modelContext implementation) installed.

Minimal example

Usage

Importing @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:
If you import @mcp-b/mcp-iframe without calling registerMCPIframeElement, the element is auto-registered as <mcp-iframe> in browser environments.

Lifecycle

  1. On connectedCallback, the element creates an internal <iframe> and mirrors attributes.
  2. When the iframe fires its load event, the element creates an IframeParentTransport and an MCP Client, then connects.
  3. On successful connection, tools, resources, and prompts are fetched from the iframe’s MCP server.
  4. Each item is registered on the parent’s document.modelContext with the element’s prefix.
  5. The mcp-iframe-ready event fires.
  6. On disconnectedCallback, all registered items are unregistered and the client and transport are closed.
Changing src, srcdoc, target-origin, or channel while connected triggers a reconnection cycle.