usewebmcp hook accepts upstream JSON Schema metadata and does not validate runtime input; it reports a Standard Schema object, such as a Zod schema, as a registration error. Standard Schema conversion and validation are MCP-B React extensions, described in the schema boundary explanation.
Validate React tool input
Install@mcp-b/react-webmcp and the schema library used in
this example:
Install the hook and Zod
inputSchema. The adapter publishes JSON Schema metadata and invokes the schema’s
validator before the handler:
useTotalTool.ts
useTotalTool() in your component. An agent call with { count: "2" }, or a local
tool.execute({ count: "2" }), returns { total: 12 }. The handler receives the number 2 and
the default limit 10. Invalid input fails before execution; async validation is awaited.
If your library supplies only Standard Schema validation, also provide its Standard JSON Schema
converter. Consult the Standard JSON Schema implementer guide
for your library’s conversion API. The core hook rejects any object with a ~standard property,
including a converter-only object; the MCP-B React adapter requires both conversion and validation.
Infer input from a JSON Schema literal
Pass an inline JSON Schema object to either hook. Both hooks preserve literal types withoutas const.
For a reusable schema constant, use as const to keep its literal information. Neither hook validates
plain JSON Schema at runtime; validate in your handler when needed.
For direct browser registration, activate the Community Group’s declarations. Install the version
the @mcp-b/* packages use so the project loads one copy of them:
Install browser declarations
Convert a Standard JSON Schema implementation outside React
For direct native or polyfilledregisterTool() calls, convert the metadata and validate in the
callback. The MCP-B adapter lives at @mcp-b/webmcp-ts-sdk/schema:
Install the adapter and Zod
total-tool.ts
registerTotalTool() in browser setup, then call its returned cleanup function when the tool
is no longer needed. Keep the spread when copying the normalized schema: it passes only JSON metadata,
so MCP calls do not apply the vendor transforms a second time. The callback invokes the schema’s own validate() method; no second validator
is needed. The standalone polyfill does not invoke that method for you. Invalid input returns an
error-flagged result instead of throwing because the polyfill reports every thrown error as the
generic Tool execution failed.
If you use BrowserMcpServer, the official MCP
server runs a preserved Standard Schema validator on MCP client calls. Direct browser calls and
native mirrors bypass that MCP validation. Use the example above to validate in the browser callback with plain JSON metadata if both routes
can execute it, or use @mcp-b/react-webmcp when registering a Standard Schema from React.
Add MCP-B output metadata
AddoutputSchema when an MCP client needs typed structured data. The SDK descriptor type checks
the input and output when you declare the descriptor separately:
search-summary-tool.ts
outputSchema is MCP-B metadata for output inference and structured MCP responses. If your handler
constructs an MCP CallToolResult directly, include schema-compatible structuredContent as well
as human-readable content. The @mcp-b/webmcp-ts-sdk reference
documents the adapter extensions and schema boundary.
outputSchema is enforced on calls through the official MCP server. @mcp-b/react-webmcp uses it
for inference and checks JSON serializability, but does not enforce the output schema on local or
direct browser calls. For React, the MCP-B hook example shows a complete
component with an output schema.
