usewebmcp is the strict-core React package. It registers tools with document.modelContext on mount and unregisters them on unmount without adding MCP-B-only hooks.
document.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 value that matches that schema for MCP-B helpers that consume it. Object, array, string, number, boolean, and null schemas are supported for type inference and hook result shaping.
Native Chrome WebMCP does not currently define or enforce outputSchema; the browser standard tool dictionary defines inputSchema.
