Six existing functions — no rewrite — made agent-ready with webmcp(fn). Try as a human, then as an agent via Inspect or Chrome WebMCP Inspector. Same functions, two interfaces.
document.modelContext.registerTool + getTools/executeTool. Other browsers: simple-webmcp/dev-polyfill shim. For production cross-browser use @mcp-b/webmcp-polyfill.searchProducts toolsearchProducts({query: "key"}) → same searchProducts function. Try empty {} in Inspect → fails (query required).addToCart, getProduct toolsAdd calls addToCart; Details calls getProduct — both are WebMCP tools.
getCart, updateCart, removeFromCart, checkout toolssimple-webmcp — same capabilityLeft: manual registerTool (schema + wrapper + AbortSignal). Right: webmcp (keeps function callable). Both register add_to_cart with productId: string enum + quantity: integer 1–10.
document.modelContext.registerTool({
name: 'add_to_cart',
description: 'Add product to cart',
inputSchema: {
type: 'object',
properties: {
productId: {
type: 'string',
enum: ['macbook','keyboard','mouse','monitor'],
description: 'Product ID'
},
quantity: {
type: 'integer',
minimum: 1, maximum: 10,
default: 1
}
},
required: ['productId','quantity']
},
execute: ({productId, quantity}) =>
addToCart({productId, quantity})
}, { signal });
inputSchema + wrapper + AbortSignal. Not callable as tool. 22 lines, all manual.import { webmcp } from 'simple-webmcp';
const addToCartTool = webmcp(addToCart, {
description: 'Add product to cart',
fields: {
productId: {
type: 'string',
enum: ['macbook','keyboard','mouse','monitor'],
description: 'Product ID'
},
quantity: { type: 'integer', minimum: 1, maximum: 10 }
}
});
// still callable:
await addToCartTool({productId:'keyboard', quantity:1});
// React: const t = useWebMCP(addToCart, {description})
9 lines with fields vs 22 raw for production types; 1 line minimal webmcp(addToCart) for prototype. fields patches inferred schema — no silent defaults for required fields.searchProducts, getProduct, getCart, addToCart, updateCart, checkout
simple-webmcp/inspect)registry.list() + document.modelContext.getTools() and lets you invoke — same path agents use. Try {} on addToCart → isError (missing productId).import { listTools, invokeTool } from 'simple-webmcp/inspect' · React: Inspector from simple-webmcp/devtools