mcpField
W
webmcp

webmcp

github.com/pillarhqDevelopment069 installsUpdated 32w ago
Repository

About webmcp

webmcp is a skill for adding callable JavaScript tools to web pages through the W3C WebMCP API. It guides developers on tool definitions, security, user confirmation, and adapting registration to SPA state.

Key features

  1. 01Define tools with schemas and execution handlers
  2. 02Validate inputs and protect sensitive data
  3. 03Request confirmation for consequential actions
  4. 04Update tool registration as SPA state changes
  5. 05Write descriptions that guide LLM tool selection

Use cases

  1. 01Expose page functions to browser AI agents
  2. 02Add callable tools to a web page
  3. 03Build human-in-the-loop agent workflows

MCP support

The skill covers the W3C WebMCP API, `navigator.modelContext`, for registering page tools that AI agents and browser assistants can call.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pillarhq/pillar-skills --skill webmcp

After installing, type/webmcpin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
rules/
descriptions.md
dynamic-registration.md
security.md
tool-definition.md
user-interaction.md

Details

From the project README

WebMCP Tools

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.

When to Apply

Reference these guidelines when:

  • Adding tools to a web page for browser AI agents
  • Registering callable functions via navigator.modelContext
  • Exposing existing page functionality to agents
  • Building cooperative human-in-the-loop agent workflows

Essential Rules

PriorityRuleDescription
CRITICALtool-definitionEvery tool needs name, description, inputSchema, and execute
CRITICALsecurityValidate params, confirm destructive actions, don't leak sensitive data
HIGHdescriptionsWrite specific descriptions — this is what the LLM reads to pick the tool
HIGHdynamic-registrationRegister/unregister tools as SPA state changes
MEDIUMuser-interactionUse agent.requestUserInteraction() for purchases, deletions, and sends

Quick Reference

1. Register a Tool (CRITICAL)
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` }] };
  }
});
2. Feature Detection (CRITICAL)
if ("modelContext" in navigator) {
  navigator.modelContext.registerTool({...});
}
3. Tool Descriptions (HIGH)
// 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"
4. User Confirmation (MEDIUM)
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" }] };
}
5. Dynamic Registration for SPAs (HIGH)
// 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]);

How to Use

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

Comments

Markdown supported