Skip to main content
Register WebMCP tools in any frontend framework by following its native lifecycle patterns. For cross-cutting patterns like conditional registration, error handling, and annotations, see Add Tools to an Existing App.

Install the runtime

React users also need a hook package. Install @mcp-b/react-webmcp (recommended) or usewebmcp alongside your chosen runtime. See Register a tool below.

Initialize at your entry point

Import @mcp-b/global once before any component mounts. The import is a side effect that installs document.modelContext. Strict-core projects call initializeWebMCPPolyfill() once, as shown above.

Register a tool

Each framework has its own lifecycle hooks for mount and unmount. Register tools on mount, unregister on unmount.
Two hook packages are available:Both handle registration on mount and cleanup on unmount automatically.

Handle SSR

Both @mcp-b/global and initializeWebMCPPolyfill() are SSR-safe: they no-op when browser globals are unavailable. Components that call document.modelContext or read page state still need to do so in client-side lifecycle code.
Mark components with 'use client'. For components that access window or document directly, use dynamic imports:
BrowserOnly.tsx

Verify registration

Open the browser console and run:
This resolves to the registered tool descriptors, including their names, descriptions, and serialized input schemas. For a richer inspection experience, see Debug and Troubleshoot.