Skip to main content
Browser transport implementations for the Model Context Protocol. Each class implements the MCP 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
Install @modelcontextprotocol/client when you use a client transport.

Minimal example

Which transport to use


Tab transports

In-page communication via window.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 a mcp-server-ready signal on start.
Tab server transport

TabServerTransportOptions

Behavior

  • Validates event.origin against allowedOrigins for every incoming message.
  • Posts mcp-server-stopped on close.

TabClientTransport

Connects to a TabServerTransport 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 uses window.postMessage with a ready handshake to handle iframe loading timing.

IframeParentTransport

Client-side transport for the parent page. Sends messages into the iframe’s contentWindow.
Iframe parent transport

IframeParentTransportOptions

Properties

IframeChildTransport

Server-side transport for code running inside an iframe. Sends messages to window.parent.
Iframe child transport

IframeChildTransportOptions


Extension transports

Communication over Chrome runtime.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 accepted chrome.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
An MCP server owns one protocol session. Create a fresh server for every port; keep shared application state outside 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

Calls chrome.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.
Setting allowedOrigins to ["*"] or targetOrigin to "*" disables origin validation. Use specific origins in production.

Common transport interface

Every transport class implements the MCP Transport interface: