Transport interface and handles JSON-RPC message parsing
and connection lifecycle. The postMessage transports validate configured
origins; extension transports operate on Chrome runtime.Port objects accepted
by application code.
Installation
Install transports
@modelcontextprotocol/client when you use a client transport.
Minimal example
Which transport to use
Tab transports
In-page communication viawindow.postMessage. Both server and client run in
the same Window; these classes do not discover or connect to another tab.
TabServerTransport
Listens for MCP messages on the current window. Broadcasts amcp-server-ready signal on start.
Tab server transport
TabServerTransportOptions
Behavior
- Validates
event.originagainstallowedOriginsfor every incoming message. - Posts
mcp-server-stoppedon close.
TabClientTransport
Connects to aTabServerTransport in the same window. Waits for a server-ready handshake before sending messages.
Tab client transport
TabClientTransportOptions
Properties
Server discovery
TabClientTransport does not have a standalone discover() method. The server-ready handshake (mcp-check-ready / mcp-server-ready) is handled internally during start().
Iframe transports
Same-origin or cross-origin communication between a parent page and an iframe. It useswindow.postMessage with a ready handshake to handle iframe loading
timing.
IframeParentTransport
Client-side transport for the parent page. Sends messages into the iframe’scontentWindow.
Iframe parent transport
IframeParentTransportOptions
Properties
IframeChildTransport
Server-side transport for code running inside an iframe. Sends messages towindow.parent.
Iframe child transport
IframeChildTransportOptions
Extension transports
Communication over Chromeruntime.Port objects. Same-extension content
scripts, sidebars, and popups can initiate a connection to a receiving extension
context. Another extension or a web page allowed by externally_connectable can
initiate an external connection by supplying the host extension ID. These
transports do not let an extension initiate a connection into an ordinary web
page, and they are not generic user-script transports. See Chrome’s
message passing documentation.
ExtensionServerTransport
Wraps one acceptedchrome.runtime.Port and therefore handles one MCP client
session. It commonly runs in the extension’s background service worker, but the
class itself accepts a port from any receiving extension context.
Accept same-extension connections
createServer() when clients need to see the same data.
For external connections, listen with chrome.runtime.onConnectExternal, check
port.sender.id or port.sender.url, and construct the transport only after the
sender passes your allowlist.
Constructor
Extension server transport constructor
ExtensionServerTransportOptions
Methods
ExtensionClientTransport
Callschrome.runtime.connect to open a port. Omit extensionId for another
context in the same extension; provide it for an external host extension. The
caller must have access to the Chrome runtime messaging API. A port disconnect
closes the MCP connection; create a new transport and reconnect the client to
start a new server session.
Extension client transport
ExtensionClientTransportOptions
Security
Security is split between the transport and the code that creates it:ExtensionServerTransport does not maintain its own sender allowlist. Validate
an incoming port before passing it to the constructor. Chrome permits external
extensions by default when externally_connectable is absent, while ordinary
web pages require an explicit matches entry.
Common transport interface
Every transport class implements the MCPTransport interface:
Related
- Transports and bridges for the conceptual architecture behind transport design
- Bridge tools across iframes for a step-by-step iframe bridging guide
- Connect desktop agents with local relay for stdio-to-browser bridging
- @mcp-b/mcp-iframe for the high-level
<mcp-iframe>custom element that wraps iframe transports - WebMCP standard API for native cross-document discovery without an MCP transport
- Chrome extension message passing for runtime port ownership and external connections
