Skip to main content
Transports are the communication layer that routes MCP messages between different browser contexts. Think of them as the plumbing that lets your tools talk to agents, whether they’re in the same tab, different tabs, or extension pages.

Prerequisites

  • @modelcontextprotocol/sdk - Official MCP SDK
  • Modern browser with ES2020+ support
  • TypeScript 5.0+ (recommended for type safety)
  • Chrome Extension Manifest V3 (for extension transports)
  • Understanding of async/await and Promises

Installation

Transport Types

Tab Transports (In-Page Communication)

Use TabServerTransport and TabClientTransport when your MCP server and client are running in the same browser tab. The transport uses window.postMessage for secure communication with origin validation.

Iframe Transports (Parent-Child Communication)

Use IframeParentTransport and IframeChildTransport for cross-origin communication between a parent page and an iframe. These transports are specifically designed for iframe scenarios and support cross-origin messaging.

Extension Transports (Cross-Context Communication)

Use ExtensionClientTransport and ExtensionServerTransport for communication between browser extension components (sidebar, popup, background) and web pages with MCP servers.

Tab Transport Examples

Server Setup (Web Page)

Create an MCP server in your web page and expose it via TabServerTransport:

Client Setup (Same Page)

Connect to the server from within the same page or from an extension content script:

Iframe Transport Examples

Server Setup (Inside Iframe)

Create an MCP server inside an iframe that can be accessed by the parent page:

Client Setup (Parent Page)

Connect from the parent page to the iframe’s MCP server:

Extension Transport Examples

Background Script Setup

The extension background script acts as a hub, aggregating tools from multiple tabs:

Content Script Bridge

Content scripts act as a bridge between the page’s MCP server and the extension:

Extension UI Client

Connect from the extension’s sidebar or popup to use tools from all connected pages:

Configuration Options

ExtensionServerTransport Options

ExtensionClientTransport Options

TabServerTransport Options

TabClientTransport Options

IframeParentTransport Options

IframeChildTransport Options

Key Features

  • Automatic Server Discovery: Tab clients can discover available servers
  • Cross-Origin Support: Configure CORS for tab and iframe transports
  • Parent-Child Communication: Iframe transports enable secure cross-origin iframe communication
  • Ready Handshake Protocol: Iframe transports handle iframe loading timing issues automatically
  • Cross-Extension Communication: Extensions can expose APIs to other extensions
  • Tool Namespacing: Extension hub prefixes tools to avoid conflicts
  • Connection Management: Automatic cleanup when tabs close
  • Keep-Alive Support: Maintain persistent connections
  • Type Safety: Full TypeScript support with proper typing

Security Considerations

  • Tab transports respect origin restrictions
  • Iframe transports validate origins on both parent and child sides
    • Always specify explicit targetOrigin (never use '*' in production)
    • Configure allowedOrigins to whitelist only trusted parent domains
    • Use postMessage API for secure cross-origin communication
  • Extension transports use Chrome’s secure message passing
  • External extension transports require externally_connectable manifest configuration
  • Server extensions should validate incoming connections from other extensions
  • Configure allowedOrigins appropriately for your use case
  • Tools execute in their original context (web page, iframe, or extension)

@mcp-b/global

Web Model Context API polyfill

@mcp-b/react-webmcp

React hooks for MCP

@mcp-b/extension-tools

Chrome Extension API wrappers

Core Concepts

Transport architecture diagrams
See also:

External Resources