API Reference

March 2, 2026 ยท View on GitHub

<WebMCPProvider>

Recommended root wrapper for apps using this library.

PropTypeDescription
namestringYour app's name
versionstringYour app's version
childrenReactNodeReact children

On mount, the provider checks for native navigator.modelContext. If absent, it installs a minimal in-memory polyfill. It cleans up the polyfill when the last provider unmounts.

useMcpTool can still run outside the provider (with a warning), but registration depends on navigator.modelContext already being present.

useWebMCPStatus()

Returns the current availability of the WebMCP API.

const { available } = useWebMCPStatus();
FieldTypeDescription
availablebooleantrue once navigator.modelContext is ready (always false on the server or outside provider)

useMcpTool(config)

Registers a tool on navigator.modelContext. Automatically unregisters on unmount.

Zod config

FieldTypeDescription
namestringTool name (must be unique)
descriptionstringHuman-readable description
inputz.ZodObjectZod schema for inputs. Handler receives typed args
outputz.ZodObjectOptional Zod schema for outputs
handler(args, client) => CallToolResult | Promise<CallToolResult>Tool implementation
annotationsToolAnnotationsOptional hints (title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint)
onSuccess(result) => voidOptional callback on success
onError(error) => voidOptional callback on error

The client argument provides requestUserInteraction(callback) for prompting the user during tool execution. When you call execute() directly, this simply invokes the callback.

JSON Schema config

Same as above, but replace input with inputSchema: InputSchema and output with outputSchema: OutputSchema. The handler receives Record<string, unknown> instead of typed args.

Return value

const { state, execute, reset } = useMcpTool({ ... });
FieldTypeDescription
state.isExecutingbooleantrue while the handler is running
state.lastResultCallToolResult | nullMost recent result
state.errorError | nullMost recent error
state.executionCountnumberTotal successful executions
execute(input?)(input?) => Promise<CallToolResult>Manually invoke the tool
reset()() => voidReset state to initial values

execute() throws if validation or handler logic fails.

The polyfill installs both navigator.modelContext (registration API) and navigator.modelContextTesting (consumer API with executeTool(), listTools()). Browser extensions and tests use modelContextTesting to discover and invoke tools.