Skip to main content
@mcp-b/react-webmcp is the full React surface for MCP-B. It supports tool registration, prompt and resource hooks, sampling and elicitation helpers, and client/provider hooks for consuming MCP servers from a React tree. Provider hooks register against document.modelContext while retaining a navigator.modelContext fallback for older preview runtimes.

Installation

For client functionality:
zod and zod-to-json-schema are optional peer dependencies. They are required only when you pass Zod v3 object maps or Zod v4 (via Standard Schema v1) as inputSchema or outputSchema.

Minimal example

Provider hooks

useWebMCP(config, deps?)

The signature matches the strict-core hook from usewebmcp with two package-specific differences:
  1. The implementation field is named handler.
  2. inputSchema and outputSchema also accept Zod v3 object maps and any Standard Schema v1-compliant schema (e.g., Zod v4 via ~standard).
Returns: WebMCPReturn Native Chrome WebMCP does not currently define or enforce outputSchema. The React hooks use it for output typing and structured MCP responses.

useWebMCPContext(name, description, getValue)

Convenience wrapper around useWebMCP for read-only context tools. It automatically sets readOnlyHint: true, idempotentHint: true, destructiveHint: false, and openWorldHint: false.

useWebMCPPrompt(config)

Registers an MCP prompt on document.modelContext.

useWebMCPResource(config)

Registers an MCP resource on document.modelContext.

useElicitation(config) / useElicitationHandler(config)

Request user input from the connected MCP client.

useSampling(config) / useSamplingHandler(config)

Request LLM completions from the connected MCP client.

Client hooks

McpClientProvider

Provider component that manages an MCP client connection and shares tools, resources, capabilities, and connection state with descendant components.

useMcpClient()

Accesses the client context. It must be used inside McpClientProvider.

Zod compatibility

@mcp-b/react-webmcp supports Zod ^3.25 || ^4.0 as an optional peer dependency.
  • Zod v3 object maps are converted to JSON Schema at registration time via zod-to-json-schema.
  • Zod v4 schemas work through the Standard Schema v1 ~standard interface.