Implement WebMCP tools that expose web app functionality to AI agents via the W3C navigator.modelContext API. Use when adding WebMCP tools, registering browser-callable tools, exposing page functionality to AI agents, or building agentic web features.
Implement tools using the W3C WebMCP API (navigator.modelContext) so AI agents, browser assistants, and assistive technologies can call structured JavaScript functions on your page.
Reference these guidelines when:
navigator.modelContext| Priority | Rule | Description |
|----------|------|-------------|
| CRITICAL | tool-definition | Every tool needs name, description, inputSchema, and execute |
| CRITICAL | security | Validate params, confirm destructive actions, don't leak sensitive data |
| HIGH | descriptions | Write specific descriptions — this is what the LLM reads to pick the tool |
| HIGH | dynamic-registration | Register/unregister tools as SPA state changes |
| MEDIUM | user-interaction | Use agent.requestUserInteraction() for purchases, deletions, and sends |
navigator.modelContext.registerTool({
name: "add-to-cart",
description: "Add a product to the shopping cart by ID",
inputSchema: {
type: "object",
properties: {
productId: { type: "string", description: "Product ID" },
quantity: { type: "number", description: "How many to add (1-100)" }
},
required: ["productId"]
},
execute: async ({ productId, quantity }) => {
await cartApi.add(productId, quantity ?? 1);
return { content: [{ type: "text", text: `Added ${quantity ?? 1} to cart` }] };
}
});
if ("modelContext" in navigator) {
navigator.modelContext.registerTool({...});
}
// Good — specific, includes what it returns
description: "Search available flights. Returns {id, airline, price, departure, arrival}. Does not book — use book-flight to complete."
// Bad — vague
description: "Search flights"
execute: async ({ productId }, agent) => {
const ok = await agent.requestUserInteraction(() =>
confirm(`Buy product ${productId}?`)
);
if (!ok) throw new Error("Cancelled");
await purchase(productId);
return { content: [{ type: "text", text: "Purchased" }] };
}
// React — register on mount, unregister on unmount
useEffect(() => {
if (!("modelContext" in navigator)) return;
navigator.modelContext.registerTool({ name: "edit-doc", ... });
return () => navigator.modelContext.unregisterTool("edit-doc");
}, [doc.id]);
Read individual rule files for detailed explanations and code examples:
rules/tool-definition.md
rules/descriptions.md
rules/security.md
rules/dynamic-registration.md
rules/user-interaction.md
For the complete guide with all patterns expanded: AGENTS.md
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer