@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.
Minimal example
CalculatorTool.tsx
Installation
Install provider hooks
@mcp-b/global. Client hooks
only require their supplied client and transport. Native WebMCP and the standalone polyfill do not
advertise MCP outputSchema metadata.
For client functionality:
Install client dependencies
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 with Standard Schema conversion and
validation, MCP annotations, output-schema inference, and automatic text/structuredContent
response formatting. Registration lifecycle, cancellation, enabled, exposedTo, and execution
state use the core hook.
The published entry point preserves 'use client'; server rendering is tested on React 19.
Returns:
WebMCPReturn, including state, execute, reset, isSupported, and registrationError.
Agent failures default to { content: [{ type: "text", text: error.message }], isError: true }.
formatError overrides this response. A handler that returns undefined yields a success response
whose text is undefined; formatOutput overrides that. Both formatters may be async and are awaited. Local failures
and cancellation always reject. state.error retains execution failures separately
from registrationError. Core-hook behavior is in the usewebmcp reference.
useWebMCPContext(name, description, getValue, options?)
Import useWebMCPContext
useWebMCP for read-only context tools. It automatically sets readOnlyHint: true, idempotentHint: true, destructiveHint: false, and openWorldHint: false.
The
enabled option has the same behavior as useWebMCP.
useWebMCPPrompt(config)
Import useWebMCPPrompt
BrowserMcpServer installed by @mcp-b/global. It does not register against a native tool-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 tool-only context.
Returns:
WebMCPResourceReturn, with isRegistered: boolean indicating whether the resource’s
registration is active.
For prompts and resources, enabled: false skips or removes the registration and sets
isRegistered to false. Re-enabling registers the latest committed configuration. Call these
hooks unconditionally and pass the condition through enabled.
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
browser-connection.ts
createBrowserConnection() in browser setup and pass its stable instances to the provider.
The framework guide covers browser-global access during server rendering.
Provider component that manages an MCP client connection and shares tools, resources, capabilities, and connection state with descendant components.
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. The tool hook runs a supplied ~standard.validate() on local and agent calls,
awaits async validation, and passes transformed output to the handler. Callers supply the schema’s input
type. JSON Schema metadata alone does not add validation.
Treat input schemas as immutable: conversion and serialization are cached by identity. Replace the
object to change its contents; equivalent serialized contents do not refresh registration.
The hook checks output JSON serializability; the official MCP server enforces the output schema
on MCP client calls. Local calls, direct browser execution, and native mirrors bypass that validation.
The tool hook registers plain JSON metadata and keeps the supplied vendor validator in its callback, so the MCP server checks the JSON Schema and the validator runs once, on every path. The SDK schema adapter converts metadata for direct MCP server registrations. The schema guide shows validation outside React.
