Skip to main content
@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
Omit @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 for toolname, tooltitle, tooldescription, toolautosubmit, and toolparamdescription.
Declare a form tool in React
Use 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
This package re-exports the same hook implementation and function signature as 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
Convenience wrapper around useWebMCP for read-only context tools. It automatically sets readOnlyHint: true, idempotentHint: true, destructiveHint: false, and openWorldHint: false.

useWebMCPPrompt(config)

Import useWebMCPPrompt
Registers an MCP prompt through the 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
Registers an MCP resource through the 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
Provider component that manages an MCP client connection and shares tools, resources, capabilities, and connection state with descendant components.

useMcpClient()

Import useMcpClient
Accesses the client context. It must be used inside 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.

Exported types