Install the runtime
- @mcp-b/global (recommended)
- @mcp-b/webmcp-polyfill (strict core)
The full runtime: polyfill, MCP server, transports, prompts, resources, sampling, and elicitation.
@mcp-b/global accesses browser APIs on import. If you use SSR, see Handle SSR for required guards.React users also need a hook package. Install
@mcp-b/react-webmcp (recommended) or usewebmcp alongside your chosen runtime. See Choose a hook package below.Initialize at your entry point
Import@mcp-b/global once before any component mounts. The import is a side effect that installs navigator.modelContext.
- 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.
| Package | Use when |
|---|---|
| @mcp-b/react-webmcp | You want the full MCP-B surface: Zod schemas, prompts, resources, sampling, elicitation |
| usewebmcp | You want strict-core navigator.modelContext tools only |
Create a reusable abstraction
React already has dedicated hook packages (@mcp-b/react-webmcp and usewebmcp), so no custom abstraction is needed. For other frameworks, extract the register/unregister lifecycle into a reusable pattern.
- Vue composable
- Svelte action
- Angular service
Handle SSR
@mcp-b/global accesses browser APIs on import, so SSR frameworks need client-side guards. If you use @mcp-b/webmcp-polyfill instead, it is SSR-safe out of the box and these guards are not needed.
- 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: