Choose a React hook
Both hooks register after React commits the component and abort the registration when it unmounts.
You do not need to manage an
AbortController in the component.
Register a tool with @mcp-b/react-webmcp
Install the complete runtime and React integration:
Install the React integration
@mcp-b/global once in your client entry point, then mount a component that calls
useWebMCP:
CalculatorTool.tsx
@mcp-b/react-webmcp reference for execution state,
prompt and resource hooks, and MCP client-provider hooks.
Register a tool with usewebmcp
Install the focused hook and provide document.modelContext through native support,
@mcp-b/webmcp-polyfill, or @mcp-b/global before the
component mounts:
Install the focused hook
Counter.tsx
usewebmcp passes input to the handler without validation and reports a Standard Schema object,
such as a Zod schema, as a registration error. To validate or transform input, follow the schema
guide.
Handle server rendering
Mount tool hooks only in client-rendered components. Importing@mcp-b/global and calling
installWebMCP() are safe during server rendering, but code that reads document,
window, or page state must run on the client.
Both published hook entry points preserve 'use client', and their server render does not register tools.
For Next.js, keep the hook inside a Client Component. Initialize the runtime above that component
so document.modelContext exists before the hook commits.
Use framework-owned guidance elsewhere
- Follow Chrome’s imperative WebMCP API guide for browser-owned registration behavior and current framework examples.
- Follow Angular’s WebMCP guide for Angular services, dependency injection, and component lifecycle integration.
- Follow Puppeteer’s WebMCP guide when a browser automation test or agent needs to discover and invoke tools.
- Consult the Community Group draft for the current
document.modelContextcontract.
Verify the mounted tools
After the component commits, inspect the page registry:Browser console
