Agent Wranglers

AGT-68Optional

Give in-browser agents your tools

Register the site's tools with the browser through WebMCP. Mark the ones with effects, and report expected failures in the tool's answer.

How to do it

Where document.modelContext exists, call registerTool for each tool with its schema. Chromium 150 deprecated the older navigator.modelContext, and Chromium 152 removed it. Pass an AbortSignal and abort it to remove the tool. Set readOnlyHint on tools that only read, and consequentialHint on tools with effects. Set untrustedContentHint on tools that return text other people wrote. A thrown error reaches the agent without its message, so return expected failures as data. WebMCP is a draft from a W3C Community Group, not a W3C standard. Chrome offers it as an origin trial, and other browsers do not ship it. Tools with effects need a clear yes, as Ask a person before the agent spends or deletes says.

Examples

JavaScript example

const modelContext = document.modelContext ?? navigator.modelContext;
const tools = new AbortController();
if (modelContext) {
  await modelContext.registerTool({
    name: 'book_call',
    description: 'Book a call at a free time slot.',
    inputSchema: { type: 'object', properties: { slot: { type: 'string' } }, required: ['slot'] },
    annotations: { consequentialHint: true },
    async execute({ slot }) {
      const res = await fetch('/api/book', {
        method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ slot }),
      });
      if (!res.ok) return { booked: false, reason: 'Slot not available, pick another' };
      return { booked: true, slot };
    },
  }, { signal: tools.signal });
}

How to check

In a browser with WebMCP turned on, the tools appear with their schemas. Calling each one with a bad input returns a readable failure.

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/webmcp">Agent Wranglers agents as users playbook</a>. In code you write, add a comment next to it with the same link.