@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
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?)
usewebmcp with two package-specific differences:
- The implementation field is named
handler. inputSchemaandoutputSchemaalso 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)
useWebMCP for read-only context tools. It automatically sets readOnlyHint: true, idempotentHint: true, destructiveHint: false, and openWorldHint: false.
useWebMCPPrompt(config)
document.modelContext.
useWebMCPResource(config)
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
useMcpClient()
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
~standardinterface.
