@mcp-b/react-webmcp is the full React surface for MCP-B. It supports tool registration, prompt and resource hooks, and client/provider hooks for consuming MCP servers.
Producer hooks register against document.modelContext. An internal fallback to the deprecated navigator.modelContext alias remains only for older preview runtimes; application code should not use it.
Installation
Install provider hooks
@mcp-b/global only when the application exclusively uses the client hooks, or when a native
WebMCP implementation supplies document.modelContext and the application only uses the core
useWebMCP tool hook. Prompt and resource hooks require the MCP-B
extensions installed by @mcp-b/global.
For client functionality:
Install client dependencies
Minimal example
Declarative form attributes
Importing this package adds React JSX declarations fortoolname, tooltitle,
tooldescription, toolautosubmit, and toolparamdescription.
Declare a form tool in React
toolautosubmit="". React drops an unknown attribute whose value is the
boolean true, so JSX shorthand (toolautosubmit) does not reach the DOM.
See the declarative API reference for the
runtime behavior.
Provider hooks
useWebMCP(config, deps?)
Import useWebMCP
usewebmcp.
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)
Import useWebMCPContext
useWebMCP for read-only context tools. It automatically sets readOnlyHint: true, idempotentHint: true, destructiveHint: false, and openWorldHint: false.
useWebMCPPrompt(config)
Import useWebMCPPrompt
BrowserMcpServer installed by @mcp-b/global. It does not register against a native strict-only context.
Returns:
WebMCPPromptReturn, with isRegistered: boolean indicating whether the prompt’s
registration is active.
useWebMCPResource(config)
Import useWebMCPResource
BrowserMcpServer installed by @mcp-b/global. It does not register against a native strict-only context.
Returns:
WebMCPResourceReturn, with isRegistered: boolean indicating whether the resource’s
registration is active.
The prompt get and resource read handlers follow the same
committed-ref lifecycle as useWebMCP:
the latest committed handler is available without replacing its registration.
Client hooks
McpClientProvider
Create an MCP client and transport
useMcpClient()
Import useMcpClient
McpClientProvider.
Calling
reconnect() while connected retries the complete tool and resource inventory. After a
one-shot transport closes, create a new transport instance and pass it to reconnect(newTransport);
reusing a closed transport is not supported by every transport implementation.
Schema compatibility
@mcp-b/react-webmcp no longer accepts raw Zod object maps. Use JSON Schema directly, or pass a
Standard JSON Schema object such as z.object(...) from Zod 4.2 or newer. outputSchema remains
JSON Schema-only because native WebMCP does not define output schema enforcement.
