usewebmcp is the strict-core React package. It registers tools with navigator.modelContext on mount and unregisters them on unmount without adding MCP-B-only hooks.
navigator.modelContext must already exist at runtime through native browser support, @mcp-b/webmcp-polyfill, or @mcp-b/global.
Installation
Minimal example
Hook
useWebMCP(config, deps?)
Returns:
WebMCPReturn
Config fields
One of
execute or handler is required. If both are present, execute wins.
ToolExecutionState
Type inference
Input inference works with two schema formats:- JSON Schema literals with
as const - Standard Schema v1 implementations such as Zod v4, Valibot, and ArkType
outputSchema when you pass a JSON Schema literal:
- the
executeorhandlerreturn type is inferred from the schema state.lastResultis typed accordingly- the MCP response includes
structuredContent
Re-registration triggers
The hook unregisters and re-registers when any of these values change:namedescriptioninputSchemareferenceoutputSchemareferenceannotationsreference- values in
deps
executehandleronSuccessonErrorformatOutput
Output schema contract
WhenoutputSchema is defined, the implementation must return a JSON-serializable object. Returning a non-object value causes an error response from the registered MCP tool.
