Skip to main content
React hooks for Model Context Protocol (MCP) - Let AI agents like Claude, ChatGPT, Cursor, and Copilot control your React components

Version

Current release: v3.0.0 — aligned with the WebMCP v3 document-first API. Provider hooks register tools against document.modelContext (the canonical v3 surface) while retaining a navigator.modelContext fallback for older preview runtimes.

When to use this package

  • You want the full MCP-B feature set from React (tools, prompts, resources, sampling, elicitation).
  • You want Zod v3 object-map support and Standard Schema v1 (e.g., Zod v4 ~standard) in hook configuration.
  • You need client/provider hooks (McpClientProvider, useMcpClient) in addition to browser-exposed tools.
@mcp-b/react-webmcp provides React hooks that expose your components as AI-callable tools via the Model Context Protocol. Build AI-powered React applications where Claude, ChatGPT, Gemini, Cursor, and Copilot can interact with your app’s functionality.
  • You only need strict-core registerTool behavior. Use usewebmcp.
  • You are not using a BrowserMcpServer-based runtime. Install @mcp-b/global first.
This package sits above the full runtime stack. It expects document.modelContext to come from a browser-native implementation or from the MCP-B runtime that wraps the strict core with BrowserMcpServer. React peer dependency: ^17.0.0 || ^18.0.0 || ^19.0.0. Zod peer dependency (optional): ^3.25 || ^4.0.
If you only want strict core WebMCP hooks (without MCP-B extension APIs like prompts/resources/sampling/elicitation), use usewebmcp instead. For client functionality, you’ll also need:
Prerequisites: Provider hooks require the document.modelContext API. Install @mcp-b/global or use a browser that implements the Web Model Context API. Provider hooks register tools with document.modelContext.registerTool(tool, { signal }) and abort the controller on unmount. The hooks retain a navigator.modelContext fallback for older preview runtimes, but document.modelContext is the canonical v3 surface. On Chrome Beta 147 native (which ignores the second arg) cleanup cannot remove the tool. Install @mcp-b/global for spec-aligned behavior.

Quick Start - Provider (Registering Tools)

Quick Start - Client (Consuming Tools)

API Overview

Provider Hooks

Client Hooks

Zod Version Compatibility

This package supports Zod 3.25.76+ (3.x only).

Documentation

For full API reference, output schemas, memoization patterns, migration guide, best practices, and complete examples, see the React WebMCP Guide.

Resources

License

MIT - see LICENSE for details