Browser transport implementations for the Model Context Protocol. Each transport class implements the MCP Transport interface and handles JSON-RPC 2.0 message serialization, origin validation, and connection lifecycle.
Installation
Peer dependency: @mcp-b/webmcp-ts-sdk (included transitively).
Minimal example
Which transport to use
Tab transports
In-page communication via window.postMessage. Both server and client run in the same browser tab.
TabServerTransport
Listens for MCP messages on the current window. Broadcasts a mcp-server-ready signal on start.
TabServerTransportOptions
Behavior
- Validates
event.origin against allowedOrigins for every incoming message.
- Tracks pending requests and sends interrupted responses during
beforeunload if the page navigates while a tool call is in progress.
- Cleans up stale requests after 5 minutes.
- Posts
mcp-server-stopped on close.
TabClientTransport
Connects to a TabServerTransport in the same window. Waits for a server-ready handshake before sending messages.
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
Cross-origin communication between a parent page and an iframe. Uses window.postMessage with retry-based ready handshakes to handle iframe loading timing.
IframeParentTransport
Client-side transport for the parent page. Sends messages into the iframe’s contentWindow.
IframeParentTransportOptions
Properties
IframeChildTransport
Server-side transport for code running inside an iframe. Sends messages to window.parent.
IframeChildTransportOptions
Extension transports
Communication between Chrome extension components using chrome.runtime.Port. Used for connecting content scripts, sidebars, and popups to the extension’s background service worker.
ExtensionServerTransport
Wraps a chrome.runtime.Port to handle a single client connection. Runs in the background service worker.
Constructor
ExtensionServerTransportOptions
Methods
ExtensionClientTransport
Connects to the extension’s background service worker via chrome.runtime.connect. Supports automatic reconnection with exponential backoff.
ExtensionClientTransportOptions
User script transports
Communication between Chrome MV3 user scripts and the extension’s background service worker. Connections arrive via chrome.runtime.onUserScriptConnect on the extension side.
UserScriptServerTransport
Identical in API to ExtensionServerTransport. Wraps a chrome.runtime.Port received from a user script connection.
UserScriptServerTransportOptions
UserScriptClientTransport
Identical in API to ExtensionClientTransport. Connects from a user script context to the extension background.
UserScriptClientTransportOptions
Security
All transports enforce origin or connection validation:
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: