Skip to main content
This guide shows you how to expose tools, resources, and prompts registered inside an iframe to the parent page’s document.modelContext using the <mcp-iframe> custom element.

Prerequisites

  • The parent page must have @mcp-b/global (or any document.modelContext implementation) installed.
  • The iframe page must also have @mcp-b/global installed and must register tools on document.modelContext.

Install the package

Add the custom element to the parent page

Replace a standard <iframe> with <mcp-iframe>. Set the id attribute to control the tool name prefix.
A tool named calculate in the iframe appears on the parent as my-app_calculate. This namespacing prevents collisions when multiple iframes register tools with the same name.

Understand namespacing

The prefix is built from the element’s id (or name attribute, or "iframe" as fallback) plus a separator character. Tool and prompt names must match the MCP pattern ^[a-zA-Z0-9_-]{1,128}$. If the id contains invalid characters, they are sanitized to underscores automatically. To change the separator character, set the prefix-separator attribute:

Configure the element

Standard iframe attributes (sandbox, allow, width, height) are mirrored to the internal iframe.

Listen for events

Refresh tools after dynamic changes

If the iframe registers new tools after the initial connection, call refresh() to re-sync:

Bridge multiple iframes

Use a distinct id for each <mcp-iframe> to keep tool names unique:
The parent page now sees tools like calc_add, calc_multiply, search_query, and search_filter.

Verify tools surface in the parent

Use the browser console to inspect registered tools:
If you have @mcp-b/global installed on the parent, you can also list tools through the standard API:

Handle cross-origin iframes

For iframes served from a different domain, set target-origin explicitly:
The iframe page must also allow the parent’s origin in its transport configuration. If you control the iframe app, ensure @mcp-b/global is loaded with appropriate origin settings.