webmcp-register-tool

Implement the WebMCP Imperative API — register tools via navigator.modelContext.registerTool() with proper schemas, execute callbacks, and lifecycle management. Use when building dynamic tool registration in JavaScript.

17 stars

Best use case

webmcp-register-tool is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Implement the WebMCP Imperative API — register tools via navigator.modelContext.registerTool() with proper schemas, execute callbacks, and lifecycle management. Use when building dynamic tool registration in JavaScript.

Teams using webmcp-register-tool should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/webmcp-register-tool/SKILL.md --create-dirs "https://raw.githubusercontent.com/OrcaQubits/agentic-commerce-skills-plugins/main/dist/antigravity/webmcp-browser-agents/.agent/skills/webmcp-register-tool/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/webmcp-register-tool/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How webmcp-register-tool Compares

Feature / Agentwebmcp-register-toolStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Implement the WebMCP Imperative API — register tools via navigator.modelContext.registerTool() with proper schemas, execute callbacks, and lifecycle management. Use when building dynamic tool registration in JavaScript.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# WebMCP Tool Registration (Imperative API)

## Before writing code

**Fetch live docs**:
1. Fetch `https://webmachinelearning.github.io/webmcp/` for the latest `registerTool` method signature and parameters
2. Web-search `webmcp navigator.modelContext registerTool specification` for the full API reference
3. Web-search `site:developer.chrome.com webmcp registerTool` for Chrome-specific guidance
4. Web-search `site:github.com mcp-b registerTool` for polyfill-compatible registration patterns

## Conceptual Architecture

### What registerTool Does

`navigator.modelContext.registerTool()` is the core imperative method for exposing a tool to AI agents. Each registered tool becomes discoverable and invocable by any agent integrated with the browser.

### Tool Definition Object

A tool object passed to `registerTool()` has these fields:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Unique tool identifier (e.g., `"addToCart"`) |
| `description` | string | Yes | Natural-language description for the agent |
| `inputSchema` | object | Yes | JSON Schema defining accepted parameters |
| `execute` | async function | Yes | Callback `(input, client) => Promise<result>` |
| `annotations` | object | No | Safety hints (`readOnlyHint`, `destructiveHint`, `idempotentHint`) |

### Execute Callback

The `execute(input, client)` callback:
- **input** — Validated against the `inputSchema`, already parsed as a JavaScript object
- **client** — A `ModelContextClient` object providing `requestUserInteraction()` for human-in-the-loop flows
- **Returns** — A Promise resolving to a JSON-serializable result object

### Tool Lifecycle

1. **Register** — `navigator.modelContext.registerTool(tool)` makes the tool discoverable
2. **Discovery** — Agent queries available tools and reads names/descriptions/schemas
3. **Invocation** — Agent calls a tool; browser validates input against schema and calls `execute`
4. **Execution** — Tool logic runs in the page's context (can use fetch, DOM APIs, session cookies)
5. **Result** — Tool returns JSON result to the agent
6. **Unregister** — `navigator.modelContext.unregisterTool(name)` removes the tool

### Registration Patterns

**Simple read-only tool:**
```js
navigator.modelContext.registerTool({
  name: "getProductInfo",
  description: "Get details about a product by ID",
  inputSchema: {
    type: "object",
    properties: { productId: { type: "string" } },
    required: ["productId"]
  },
  annotations: { readOnlyHint: true },
  async execute(input) {
    const res = await fetch(`/api/products/${input.productId}`);
    return await res.json();
  }
});
```

**Transactional tool with user confirmation:**
```js
navigator.modelContext.registerTool({
  name: "placeOrder",
  description: "Place the current order and charge the saved payment method",
  inputSchema: { type: "object", properties: {}, required: [] },
  annotations: { destructiveHint: true },
  async execute(input, client) {
    const confirmed = await client.requestUserInteraction((resolve) => {
      showConfirmDialog("Confirm order?", resolve);
    });
    if (!confirmed) return { status: "canceled" };
    const res = await fetch("/api/orders", { method: "POST" });
    return await res.json();
  }
});
```

### Naming Best Practices

- Use camelCase for tool names (`searchProducts`, not `search-products`)
- Be specific and descriptive (`addToCart` not `add`)
- Group by domain: `cart.add`, `cart.remove` or `addToCart`, `removeFromCart`
- Avoid generic names that could conflict across sites

### Description Best Practices

- Write descriptions for the AI agent, not the end user
- Be precise about what the tool does, its side effects, and what it returns
- Mention constraints: "Requires the user to be logged in" or "Only available for items in stock"
- Avoid jargon the agent may not understand

### Error Handling

Tools should handle errors gracefully:
- Return structured error objects rather than throwing exceptions
- Include error codes and human-readable messages
- Distinguish between user errors (bad input) and system errors (server failure)

### Dynamic Registration

Tools can be registered and unregistered dynamically based on page state:
- Register cart tools only when the cart page is active
- Register checkout tools only when the user is authenticated
- Unregister tools when navigating away from relevant pages
- Use `clearContext()` on page transitions in SPAs

Fetch the specification for exact method signatures, return types, and any new fields before implementing.

Related Skills

webmcp-user-interaction

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement human-in-the-loop flows with requestUserInteraction() — confirmation dialogs, approval workflows, and user prompts during tool execution. Use when building tools that require user consent before performing actions.

webmcp-tool-schemas

17
from OrcaQubits/agentic-commerce-skills-plugins

Design JSON Schemas for WebMCP tool inputs and outputs — proper types, constraints, nested objects, and agent-friendly documentation. Use when defining or refining tool schemas for agent consumption.

webmcp-tool-annotations

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement WebMCP tool annotations — readOnlyHint, destructiveHint, idempotentHint safety hints that inform browser permission prompts and agent behavior. Use when marking tools with appropriate safety metadata.

webmcp-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test WebMCP tools with AI agents — Chrome DevTools integration, agent testing workflows, tool discovery verification, and end-to-end commerce flow testing. Use when validating that tools work correctly with real AI agents.

webmcp-setup

17
from OrcaQubits/agentic-commerce-skills-plugins

Set up a WebMCP project — enable Chrome flags, install MCP-B polyfill, scaffold tool registration, and configure development environment. Use when starting a new WebMCP-enabled website from scratch.

webmcp-security

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement WebMCP security best practices — permission model, data minimization, honest descriptions, input validation, fingerprinting prevention, and fraud mitigation. Use when auditing or hardening WebMCP tool implementations.

webmcp-polyfill

17
from OrcaQubits/agentic-commerce-skills-plugins

Set up and use the MCP-B polyfill — vanilla JS and React packages that implement navigator.modelContext for browsers without native WebMCP. Use when developing for browsers that don't yet support WebMCP natively.

webmcp-mcp-bridge

17
from OrcaQubits/agentic-commerce-skills-plugins

Integrate WebMCP client-side tools with backend MCP servers and UCP endpoints — bridge browser-based agent interactions with server-to-server protocols. Use when connecting front-end WebMCP to existing backend API infrastructure.

webmcp-context-provider

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement the WebMCP provideContext API — bulk tool registration, contextual metadata, page state sharing, and dynamic context updates. Use when providing rich context and multiple tools to agents simultaneously.

webmcp-commerce-tools

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement commerce-specific WebMCP tools — product search, cart management, checkout, returns, subscriptions, and support. Use when building agentic shopping experiences on e-commerce websites.

webmcp-authentication

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement WebMCP authentication patterns — browser session inheritance, cookie-based auth, role-gated tool registration, and conditional tool exposure. Use when managing which tools are available based on user authentication state.

nlweb-tools-framework

17
from OrcaQubits/agentic-commerce-skills-plugins

Design and implement NLWeb tools — the per-Schema.org-type handlers that turn a query into a specialized response (search, item_details, compare_items, ensemble, recipe_substitution, accompaniment, conversation_search, etc.). Covers `tools.xml`, the ToolSelector router, builtin handlers in `methods/`, writing a custom tool with a `<returnStruc>` contract, and disabling tool selection for raw retrieval. Use when extending NLWeb beyond the default query → results flow.