WebMCP Tools: How to Build and Test Them

WebMCP tools registered on a web page for AI agents to call

WebMCP tools let a web page expose specific actions as JavaScript functions that AI agents can discover and call directly. Today agents lean on screenshots, the DOM and the accessibility tree to understand a page, which is bulky and depends on how well the site is built. WebMCP is a draft browser API meant to skip that step.

The proposal is being developed in the W3C’s Web Machine Learning Community Group, mostly by people from Google and Microsoft. A page registers tools, the browser lists them for agents, and an agent calls one to fetch information or perform an action.

Where browser support stands

WebMCP exists only in Chromium browsers, behind a flag or an origin trial, and was developed mainly by people at Chrome and Edge. Polypane lets developers inspect and test tools without flipping a flag. Mozilla’s standards position is neutral for now, though it’s taking part in the discussion. Apple opposes the proposal. It sees an agent as a kind of assistive technology that should use the same page as everyone else, and it has privacy and security concerns. The W3C’s Technical Architecture Group is still reviewing it.

The spec changes every few weeks, and some changes have broken existing code. The API moved from navigator.modelContext to document.modelContext, for example. The code in this guide works in Chromium 160, the engine in Polypane 32. Since early November 2026 there has also been an official W3C polyfill that adds document.modelContext to browsers without it, although an agent still needs a browser with built-in support to call the tools.

Polypane with this article on the left, scrolled to the booking demo, and the WebMCP panel on the right. In the panel the book_table tool is open with its form filled in and a completed tool call below it. The demo shows the confirmation of the booking.
Image: polypane.app

Registering a tool

First check that document.modelContext exists, then call registerTool(). Each tool is an object with a name, a plain-language description, an inputSchema written in JSON Schema and an execute function. An outputSchema (added to the spec in November 2026) and annotations are optional. If the name is invalid or already used, or the description is empty, the returned promise rejects, so add a catch().

The demo registers a book_table tool for a fictional restaurant. Names can contain letters, numbers, underscores, dashes and dots, must be unique on the page, and should stay under 30 characters even though 128 are allowed. Snake_case is the emerging convention.

The description tells the agent whether to call the tool, so say what it does and what it returns, within about 500 characters. Each schema property needs its own description of 150 characters or fewer.

Annotations and validation

Annotations are hints to the agent:

  • readOnlyHint marks tools that change nothing.
  • untrustedContentHint marks tools that return content you didn’t write, such as reviews.
  • consequentialHint marks actions that can’t be undone, like placing an order.

Polypane asks for permission before an agent calls a consequential tool, and an agent can use the hint to check with the user first.

The browser doesn’t validate input against your schema, so execute should. A validator such as Ajv can reuse the same inputSchema. If an agent tries to book a table for 80 people, the error says guests must be 8 or fewer. Always throw on bad input, because the agent receives the message and can retry. Guessing what the agent meant can leave both agent and user believing something happened that didn’t. Keep return values to roughly 1,500 characters.

To remove a tool, pass an AbortSignal when registering and call abort() later, which helps when a tool only makes sense for logged-in users.

Designing tools well

Each tool should do one thing, and a page should probably stay near a dozen tools, since too many overwhelm an agent and too few make features hard to find. Show the result on the page too, so users can see what a tool did and continue from there. Only build tools for things people can do on the page themselves, or visitors without agents are left out.

An earlier spec version allowed form-based tools through toolname and tooldescription attributes on a form. That still works in Chrome and Polypane, but the declarative approach has been dropped from the spec so the group can focus on JavaScript tools. Form-based tools may return later.

Testing and the open questions

Polypane’s WebMCP panel shows registered tools, flags mistakes in definitions, lets you call a tool by hand, shows results and keeps a history of calls. An agent can also test a page through it.

The author’s view is that WebMCP answers a real need for a standard way to interact with pages, but shouldn’t be limited to AI agents. A browser button for booking a table would serve everyone. There’s also concern that tools could exclude users without agents. Adding a tool is low risk for now, as long as you’re ready to adapt when the draft changes.

Source: polypane.app

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.