Install the runtime
- @mcp-b/global (recommended)
- @mcp-b/webmcp-polyfill (strict core)
The full runtime: polyfill, MCP server, transports, prompts, resources, and direct access to the official MCP server.
@mcp-b/global checks for window and document before auto-initializing, so the import is
SSR-safe. Tool registration still belongs in client-side lifecycle code.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.
- React
- Vue
- Svelte
- Angular
- Next.js
- Astro
- Vanilla JS
Register a tool
Each framework has its own lifecycle hooks for mount and unmount. Register tools on mount, unregister on unmount.- React
- Vue
- Svelte
- Angular
- Next.js
- Astro
- Vanilla JS
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.
- Next.js
- Nuxt / Vue SSR
- SvelteKit
- Angular Universal
- Astro
Mark components with
'use client'. For components that access window or document directly, use dynamic imports:BrowserOnly.tsx
