# Getting started with WebMCP: building and testing tools

The web is an amazing place where we do most of our day-to-day things. So it's no wonder that every AI agent wants to be able to interact with it like we do.

Currently, they rely on screenshots, the DOM and accessibility tree to understand what's on the page, but those are frequently large and depend on the site doing a somewhat decent job of structuring its content.

WebMCP is an in-development specification designed to solve this problem by making specific actions that a page can run callable as JavaScript "tools" that agents can discover and invoke directly, skipping over the page.

In this article I'll explain what WebMCP is, assess its current state, and look at how you can implement and test your tools without needing an agent.

## What is WebMCP?

WebMCP is a proposal for a browser API that is being worked on in the W3C's Web Machine Learning Community Group, mostly by people from Google and Microsoft. With it, a web page can register _tools_ (JS functions). AI agents can get a list of tools from the browser, and then call a specific tool to get information or perform an action.

As mentioned in the intro, the benefit of registering tools like this is that they're very easy for external tooling to discover and invoke: their formatting and input is standardized and they can be called directly.

That means external tooling does not have to understand the (often unique and specific) DOM structure of your page in order to find out how to interact with it.

## What do browsers think of it?

At the time of writing WebMCP is only available in Chromium browsers and developed primarily by folks at Chrome and Edge. Chromium browsers, like Polypane, have support for it but the full specification is still being written and frequently changes between releases as the specification evolves.

Looking at the other browser engines, both Mozilla and Apple are not on board yet.

Mozilla's [standards position](https://github.com/mozilla/standards-positions/issues/1412) is neutral for now, though they seem engaged in the discussion on how it should work and what it should do.

Apple currently [opposes](https://github.com/WebKit/standards-positions/issues/670) WebMCP. They see an agent as a kind of assistive technology (like screen readers) that should use the same page as everyone else, and they have concerns about privacy and security.

The W3C's Technical Architecture Group is [still reviewing the proposal](https://github.com/w3ctag/design-reviews/issues/1238).

### Our stance

I think WebMCP answers a clear need for a standardized way to interact with web pages that just happens to work well for LLMs, but I don't see why it needs to be specifically built for AI agents.

Wouldn't it be great if the browser just had, for example, a "Book table" button in the browser chrome whenever you visited a restaurant's page, and it would have all your info available and you wouldn't have to bother with the dinky form on the page itself? _(Hey, remember 'the semantic web'?)_

That's a future I'd love to see, and WebMCP could be a step towards that as long as we're not locking it into AI agents only.

Additionally, there is a real concern that the presence of WebMCP could lead to exclusion or discrimination against users who do not have access to AI agents, potentially marginalizing users.

### Support for WebMCP in browsers

As mentioned earlier, WebMCP is currently only available in Chromium browsers, behind a flag or origin trial (meaning you need to enable it manually or be part of the trial). The exception is [Polypane](/), which lets you inspect and test WebMCP tools without needing to enable any flags.

### WebMCP will change

WebMCP is a draft that changes every few weeks, and those changes have already broken existing code a number of times.

The API is small and experimental so it's not too much of a hassle. For example, one of the changes is that the API moved from `navigator.modelContext` to `document.modelContext`. This is manageable as long as you're prepared to adapt to those changes when they happen.

The code in this article works in Chromium 160, which is what Polypane 32 uses. If you're reading this much later, we've probably updated it but you can always check the [specification](https://webmachinelearning.github.io/webmcp/) for what changed.

## Adding a tool to your site

You add a WebMCP tool to your site by registering it with `document.modelContext.registerTool()`. This tells the browser about the tool and how to use it.

For this article I made a small demo for a restaurant where you can book a table. It's part of this page, and it's also registered as a WebMCP tool. If you're reading this in Polypane, open the WebMCP panel and you'll find the tool there.

Book a table

WhoName \*Email \*Guests \*

WhenDate \*Time \*SeatingInsideTerraceAt the bar

Notes

\* requiredBook table

So let's see how to add a tool to your page. Before you add a tool, make sure your page has a `document.modelContext` available:

```js
if (document.modelContext) {
  // safe to add tools
}
```

When you've done that, you can call `document.modelContext.registerTool()` to register your tool with the browser. Each tool is an object with the following properties:

*   a `name` that identifies the tool,
*   a `description` in plain language that explains what the tool does,
*   an `inputSchema` that describes the input it accepts, written as [JSON Schema](https://json-schema.org/),
*   optionally an `outputSchema` that describes what the tool returns,
*   optionally an `annotations` object that provides additional information about the tool,
*   and an `execute` function that runs when the tool is called.

Here's the tool that books a table in the demo. You can see that it's schema matches the form you see above.

```js
if (document.modelContext) {
  document.modelContext
    .registerTool({
      name: 'book_table',
      description:
        `Book a table at Trattoria Polypane. Returns a confirmation with the ` +
        `booking reference. A booking can not be changed afterwards.`,
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Name the booking is under' },
          email: { type: 'string', description: 'Email address to send the confirmation to' },
          date: { type: 'string', format: 'date', description: 'Date of the booking, in YYYY-MM-DD format' },
          time: {
            type: 'string',
            description: 'Arrival time in 24 hour HH:MM format. The kitchen is open from 17:00 to 22:00',
          },
          guests: { type: 'integer', minimum: 1, maximum: 8, description: 'Number of guests, from 1 to 8' },
          seating: {
            type: 'string',
            enum: ['inside', 'terrace', 'bar'],
            description: 'Where the guests want to sit. Defaults to inside',
          },
          notes: { type: 'string', description: 'Allergies, a high chair or other requests' },
        },
        required: ['name', 'email', 'date', 'time', 'guests'],
      },
      annotations: { consequentialHint: true },
      async execute(input) {
        if (!validate(input)) {
          throw new Error(ajv.errorsText(validate.errors));
        }
        return bookTable(input);
      },
    })
    .catch((error) => {
      console.warn('Could not register the book_table tool:', error);
    });
}
```

When you register a tool with an invalid name, a name that's already in use or an empty description, the promise that `registerTool()` returns gets rejected and your tool is not registered. I added a `catch()` so that I get a warning in the console when that happens.

Let's go over the parts of this tool in more detail.

### Name and description

The `name` can contain letters, numbers, underscores, dashes and dots but not spaces. It also is the identifier, so it needs to be unique for your page. It can be 128 characters long, but recommended practice is to keep it below 30 characters. The concensus that I've seen so far is to use snake\_case for tool names.

An agent uses the `description` to decide if it should call your tool, so use it to say what the tool does. Always include what the tool returns as well. This helps the agent understand the expected output without having to call the tool first, and makes it more likely for your output to be used correctly.

Agents have limits on how much text they take in, so the [recommendation](https://developer.chrome.com/docs/ai/webmcp/secure-tools) is to stay within about 500 characters for the description of a tool.

### Input schema

The `inputSchema` defines the structure of the input that the agent should provide when calling your tool. It uses [JSON Schema](https://json-schema.org/) to describe the expected properties, their types, and any constraints.

Not everyone likes JSON Schema, but it allows for a very precise and structured way to define the input your tool expects (I'm a fan). Explaining how to set up a JSON Schema is, however, a little outside of the scope of this article.

Each item in your schema should have a `description` property that explains what the agent should send for that value, and it should be relatively short, at most 150 characters long.

### Output schema (optional)

In November 2026 an `outputSchema` was added to the specification. It works like the `inputSchema`, but it describes what your `execute` function returns. This can be useful for when your tool returns structured data, or references that are important for other tools or subsequent actions. If you have a tool that just returns a simple status, value or string, you can instead rely on the `description` to explain the output.

For `book_table` that is the booking that was made:

```js
outputSchema: {
  type: 'object',
  description: 'The booking that was made',
  properties: {
    reference: { type: 'string', description: 'Reference of the booking, e.g. TP-20261210-4' },
    date: { type: 'string', format: 'date', description: 'Date of the booking' },
    time: { type: 'string', description: 'Arrival time in 24 hour HH:MM format' },
    guests: { type: 'integer', description: 'Number of guests' },
  },
},
```

Add one to tools that return more than one value, and to tools that return something that another tool needs, like the booking reference here.

The `outputSchema` is new and agents might not all use it yet, so explain the expected output in your `description` as well.

### Annotations (optional)

With annotations you let the agent know what kind of tool it's dealing with:

*   `readOnlyHint` is for tools that don't change anything.
*   `untrustedContentHint` is for tools that return content you didn't write yourself, like reviews or comments.
*   `consequentialHint` is for tools that do something that can't be undone, like placing an order.

If a tool does something that the user can't undo, always add `consequentialHint`. Polypane asks you for permission before an agent calls a tool that has it, and an agent can use it to check with the user first.

Our `book_table` tool doesn't _really_ book you a table (sorry), but we marked it with `consequentialHint` to indicate that it performs an action that can't be undone.

Exactly what `readOnlyHint` means is up to you. For example, on our [color contrast checker](/color-contrast/) tool, we don't add a hint because the function also updates the values on the page. But you _could_ argue that that still counts as read-only from the perspective of the agent, since it doesn't change the underlying content.

These annotations end with `Hint` for a reason: it's your way of giving guidance to the agent, and it's your judgment call based on how you want the agent to interpret your tool.

[

### Polypane has everything you need to build great sites

Learn about Polypane](/)

### The execute function

The `execute` function gets the input the AI agent generated as its argument, an object that should follow the JSON schema. The browser doesn't validate against the schema so you should validate the input before using it, and throw an error if it doesn't match. Then you can use it to perform the action it should take.

Your `inputSchema` already says what the input should look like. Use a JSON Schema validator like [Ajv](https://ajv.js.org/) to check the input against the schema you already have. That's where the `validate()` function in the example above comes from:

```js
import Ajv from 'ajv';
import addFormats from 'ajv-formats';

const ajv = new Ajv();
addFormats(ajv); // for the date format
// inputSchema is the same object you pass to registerTool()
const validate = ajv.compile(inputSchema);
```

Then `execute` only has to call it:

```js
async execute(input) {
  if (!validate(input)) {
    throw new Error(ajv.errorsText(validate.errors));
  }
  return bookTable(input);
},
```

For example when an agent tries to book a table for 80 people, this throws an error that says `guests` has to be 8 or lower.

Of course, `bookTable()` would still need to perform its own checks and handle the actual booking logic, such as checking availability and updating the reservation system.

Always throw an error when the input isn't right. When `execute` throws an error the call fails and the agent gets an error back, so with a clear message it can try again with better input.

If you try to guess what the agent meant and return something that might be wrong, the agent and your user both think it did what they asked for.

The recommended maximum length for the return value is around 1500 characters, and it can be data or freeform text.

### Removing a tool again

If your page doesn't always offer the same tools, for example because one of them only makes sense when the user is logged in, you can pass an `AbortSignal` when you register the tool and abort it to remove the tool again:

```js
const controller = new AbortController();
document.modelContext.registerTool(tool, { signal: controller.signal });

// Later, when the tool should no longer be available
controller.abort();
```

## Practical advice for tool design

When you are designing your own tools, think about how they will be used by both the agent and the user, and make sure they map well to the actions your user already takes on your page.

### How many tools should you add to a page?

There is a balance between having too many tools, which can overwhelm the agent, and having too few, which can make it harder for the agent to find the right functionality.

Broadly speaking, make sure each tool does one thing (a good programming principle on its own) and offer tools for the most important parts of the page. Practically, I'd say limit it to about a dozen.

### Show the result on the page

I think that the user should always be able to see what a tool did on the page. If your tool does anything other than returning data, like changing a setting, adding something to a list or making a booking, you should also update the page so that it shows the result. That way the user doesn't have to take the agent's word for it, and they can continue on the page from where the agent left off.

Our [color contrast checker](/color-contrast/) has a `check_color_contrast` tool that does this. An agent calls it with a foreground and a background color and gets the contrast and a list of suggested colors back. But the tool also fills in both colors on the page, so the user gets the same preview, ratings and suggestions that the agent got.

For the same reason, only make tools for things that people can also do on the page themselves. When something only works through a tool, everyone that visits your site without an agent is left out.

### Using the polyfill

Since the beginning of November 2026 there is an official [WebMCP polyfill](https://github.com/w3c-oss/webmcp-polyfill), published by the W3C and maintained by people from the community group that works on the specification. It adds `document.modelContext` to browsers that don't have it, so the code that registers your tools runs in every browser.

An agent still needs a browser with built-in support to call your tools, and the polyfill doesn't change that. But you can use it to let an assistant that's part of your own site use the same tools that browser agents get.

### What about forms?

A previous version of the specification included form-based tools, which allowed developers to create tools directly from HTML forms in a declarative way.

That still works in Chrome and Polypane. If you add the `toolname` and `tooldescription` attributes to a `<form>`, the browser will treat it as a tool where all the form fields with their atttribute values (like `required`, `min` etc.) are used as input for the tool.

This declarative approach has since been taken out of the specification, with the reason being that they want to first focus on the JavaScript-based tools. Form-based tools may be reconsidered in the future, but for now the focus is on JavaScript.

It's harder to build declarative APIs so it makes sense to order it this way when things are still being figured out. But having tooling be form-based forces developers to consider features as primarily for users (the form needs to make sense for people) rather than giving agent-using people a better experience. I think that's better.

Polypane's WebMCP panel supports them, so if you use them you can test them in the same way as the JavaScript tool in the rest of this article.

## Testing your tools in Polypane

If you have a WebMCP tool on your site, you need to test that it works. You could start asking your agent all sorts of things in the hope of 1) triggering the right tool and 2) getting the correct response, but that doesn't seem like a very reliable way to test your tools, nor does it make it easy to reproduce issues when something goes wrong.

That's why Polypane has a [WebMCP panel](/docs/webmcp-panel/). It shows you the tools on your page in a structured way, so you can deal directly with the inputs and outputs to judge the behavior of your 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.](/static/app-ffee59115a85324b8801452a3c24c5ec.png)

### Checking that your tools are registered

Open the panel and select the WebMCP tab. It lists all the tools on the page with their name and the first two lines of their description.

![The Polypane WebMCP panel listing one tool, book\_table, with its description and a consequential badge.](/static/list-f173592c14dc9d88ba1f5db1ff1bfb84.png)

The icon on the right shows if a tool comes from a script or from a form, and when you hover over it you see where it was registered. Tools that are read-only, return untrusted content or are consequential get a badge, so you can check that your annotations ended up on the tool.

If a tool is missing from this list then it wasn't registered, and you can look in the console to find out why.

### Finding mistakes in your tool definitions

A tool can work fine when you call it yourself and still be hard for an agent to use, for example because its description is too long or because a parameter has no explanation. The browser accepts those tools without complaining.

Polypane checks your schema to see if it makes sense. In the overview, it shows the number of errors and warnings for each tool, and you can click on a tool to see the details of each issue.

For example, here is a version of our `book_table` tool where the schema has some mistakes:

![The Polypane WebMCP panel for the book\_table tool, showing two errors and a warning: guests has the unknown type int, the property email is listed as required but undefined in properties, and the property name has no description.](/static/validation-c543cf49fdde9f40f435916fe05933fb.png)

Polypane found three issues with the `book_table` tool. Where it makes sense we suggest a fix too:

*   `guests` has the type `int`, which doesn't exist in JSON Schema.
*   `email` is listed as required, but I never added it to the properties. An agent would be asked to send a parameter that the tool doesn't describe.
*   `name` doesn't have a description, so an agent has to guess what to send.

### Calling a tool

Polypane automatically creates a form based on your input schema as well as a free-form JSON field. Both of these are kept in sync, so you could start with the form and then add things in the JSON field that might not (yet) be part of your input schema.

![The book\_table tool opened in the Polypane WebMCP panel, with a generated form: text fields for name, email, time and notes, a date picker for date, a number field for guests, a select for seating and a Run button.](/static/form-0f98abaf81bd00a45a04cb2d89088a8b.png)

Each field shows all the info we have. If you find you're missing information to properly fill in this form, it's probably a sign to improve your input schema. You can toggle over to the input schema too to see what the tool expects.

![The Polypane WebMCP panel with the JSON tab selected, showing the input schema of the tool and below it an editable JSON field with the input.](/static/json-c2fcc81da006a9706e27d73747e4ffc5.png)

Fill in the form and click **Run** to call it in all open panes (or specific ones).

### Reading the results

Each time you run a tool, the call gets added to the list of tool calls below the form. We keep all previous calls in the list so you can review them and compare results. They stick around between page reloads so that you can change and update your tools and still have the history available for reference.

![The list of tool calls in the Polypane WebMCP panel, both from automation. A completed call shows the booking that was returned. A call that resulted in an error shows its input and the error message.](/static/calls-873394bde615e26ce0044b0701f8b5dd.png)

As the function is called, the status will go from pending to completed or error depending on the outcome.

Once done, you can see when the call was made and how long it took, where it came from (this panel, or an agent through our [Automation](/docs/automation/)), as well as the output.

If you want to check the input for a call, click "Show input" and you'll see the input along with the output. In the screenshot above the second call resulted in an error, and from the input and the error message you can tell that's because it tried to book a table for 80 guests.

There are a few icons that make it easy to replay a call (for example because you updated the execute function), edit as new or remove this result. These make it really easy to work and iterate on your tools during development.

### Letting an agent test it through Polypane

Once your tools work when you call them through the panel, you'll want to know what an actual agent makes of them. With [Polypane Automation](/docs/automation/) you can connect your AI tool to Polypane and ask it things like:

*   "List the WebMCP tools on this page and check them for issues"
*   "Try to book a table for 12 people with the book\_table tool and tell me what happens"

Testing this through Polypane gives you more developer feedback than elsewhere, because our MCP validates the input against the schema and gives the agent feedback when something is wrong with it.

The agent can still choose to send invalid input anyway to test how your tool deals with it. For tools you marked as consequential, Polypane asks you for permission first.

![A Polypane popup asking 'Allow Claude Desktop to do something risky?' for a call to the book\_table tool, which the page marks as consequential. It has a 'Show the input' toggle, a 'Remember my choice' checkbox and Deny and Allow buttons.](/static/confirm-7c0a03f5e9b42bf39ca7adcc0ee4445c.png)

Every call an agent makes shows up in the WebMCP panel too, so you can see exactly what happened.

## Should you add WebMCP to your site?

WebMCP is an interesting API that can let agents, and hopefully in the future people, interact with your pages in a faster and more convenient way.

It's still in development, but adding a tool to your site can be done without much risk, and lets you start experimenting with it right away.

Polypane provides a convenient way to test and iterate on your tools directly within the browser, giving you immediate feedback and a clear history of all tool calls.

Not using Polypane yet? [Start a free trial](/download/) and open this article to call your first tool.

---

Polypane is the browser for web developers. Try it at https://polypane.app.
