Skip to main content
Start with the browser standard. Add MCP-B packages only when you need behavior beyond that standard.

Decision flowchart

Ask these questions in order:
  1. Does the target browser ship document.modelContext natively? If yes, and that covers your use case, you may not need any package at all.
  2. Do you need compile-time types without any runtime? Install @mcp-b/webmcp-types as a dev dependency.
  3. Do you need the WebMCP standard in browsers that lack native support, and nothing else? Install @mcp-b/webmcp-polyfill.
  4. Do you need MCP bridge transport, callTool, listTools, prompts, resources, elicitation, or sampling? Install @mcp-b/global.
  5. Do you need React hooks? Choose usewebmcp for strict core, or @mcp-b/react-webmcp for the full MCP-B surface.

Package comparison

If you want the WebMCP standard only

Install the polyfill. It adds document.modelContext and stays on the strict WebMCP path. It does not add MCP-B extension methods.
main.ts
The polyfill is non-destructive. If document.modelContext already exists natively, initialization is a no-op. For type inference on tool arguments, pair the polyfill with @mcp-b/webmcp-types:
See Use Schemas and Structured Output for details.

If you want the full MCP-B runtime

Install @mcp-b/global. It layers the MCP-B runtime on top of the WebMCP surface.
main.ts
@mcp-b/global auto-initializes on import. It installs the polyfill first, then replaces document.modelContext with a BrowserMcpServer that keeps the core behavior and adds MCP-B-only methods such as callTool, listTools, prompts, resources, and transport support. If you need to customize before initialization (for example, to restrict allowed origins), set options on window.__webModelContextOptions before loading the script:

If you want React hooks

CounterTool.tsx
usewebmcp expects document.modelContext to exist. Provide it with @mcp-b/webmcp-polyfill or @mcp-b/global.

If you only need types

Install @mcp-b/webmcp-types as a dev dependency. It has no runtime code and no side effects.
Add it to your tsconfig.json to get document.modelContext typing:
tsconfig.json
This is useful when you are writing against a native browser implementation or a third-party polyfill and want type-safe tool descriptors without adding any runtime dependency.

How the layers relate

For a deeper look at the layering rationale, see Runtime Layering. The Strict Core vs MCP-B Extensions page covers the boundary between the specification surface and MCP-B additions.