Skip to main content
Use JSON Schema for the browser-facing inputSchema. MCP-B can infer literal schemas, convert Standard JSON Schema implementations, and attach outputSchema metadata for typed MCP results. The WebMCP Community Group draft remains the authority for the browser’s tool dictionary.

Infer input from a JSON Schema literal

Install the declaration package when you want TypeScript to infer the handler input:
Install the type declarations
Preserve literal information with as const satisfies JsonSchemaForInference: If a schema is loaded or widened at runtime, narrow the handler input yourself. MCP-B cannot infer specific fields from a broad runtime type. See the @mcp-b/webmcp-types reference for supported inference keywords.

Convert a Standard JSON Schema implementation

MCP-B hooks accept Standard JSON Schema v1 objects directly. Pass a Zod 4.2 schema as the inputSchema in usewebmcp or @mcp-b/react-webmcp. For direct registerTool() calls, convert the schema through the MCP-B adapter and validate inside the handler:
Install the adapter and Zod
search-tool.ts
Convert refinements into JSON Schema where possible, but still parse untrusted input inside the handler. Browser execution does not run your schema library before calling the handler.

Add MCP-B output metadata

Add outputSchema when an MCP client needs typed structured data. Declare the descriptor separately so ToolDescriptorFromSchema checks the returned value:
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 package reference lists the output inference types.

Check the agent-facing schema

After registration, inspect the emitted schema in Chrome’s WebMCP DevTools panel. Then run the Lighthouse WebMCP schema validity audit. Use Chrome’s WebMCP best practices for names, descriptions, and schema design. Use WebMCP evals to test whether agents select the tool and supply the expected arguments.