Skip to the page
Tactile UI

Let AI agents use your kit parts (WebMCP)

WebMCP lets a web page tell an AI agent what it can do. The page registers tools, each with a name, one sentence and its inputs, and the agent calls a tool instead of guessing at buttons from a screenshot. This page shows how to register one for a range, a toggle key and the commit key. It changes no kit code, and nothing registers unless your code asks.

On this page
  1. Where WebMCP stands
  2. How a tool is registered
  3. A range
  4. A toggle key
  5. The commit key, behind the alert dialog
  6. The one limit
  7. Keep tools short

Where WebMCP stands

It is an experiment (checked 22 Nov 2026). Chrome runs it as an origin trial from Chrome 149, and Edge from Edge 150, so a site signs up for the trial to use it. Firefox's position is neutral and Safari's is opposed, so for now it is Chromium browsers only. Chrome says it means to ship it to everyone, but it has listed no shipping milestone yet. The API is still changing, so the code below checks for it first and does nothing where it is missing. Your page behaves the same without it.

This is not the docs MCP in Install with shadcn, and MCP. That one helps your coding agent while you build. WebMCP is for the agents your visitors bring to the finished app.

How a tool is registered

document.modelContext.registerTool(tool, { signal }) takes a name, a description, an input schema and an execute function that returns a result. Older guides use navigator.modelContext, so the code tries both. Calling abort() on the signal removes the tool again.

Use the words you already gave a screen reader. A part's label is its tool's name and description, so there is one source of truth and no second set of words to keep in step. Take the label from your own markup, never from text a visitor typed.

A range

The range's label is its <legend>. Its two caps read and write as values, a pair of low then high. The caps never cross, so the tool refuses a low above the high. Setting values does not fire events, so the tool then fires the change event the part's native inputs fire for a person.

Put all three examples in one module script, in this order.

import { toggleKey, confirmDialog } from './kit/kit.mjs';

const mc = document.modelContext ?? navigator.modelContext;
if (mc) {
  const off = new AbortController();           // off.abort() removes every tool below
  const opts = { signal: off.signal };
  const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '');

  const range = document.querySelector('tui-range');
  const rangeLabel = range.querySelector('legend').textContent.trim();   // "Price"
  const input = range.querySelector('input[type="range"]');
  await mc.registerTool({
    name: `set_${slug(rangeLabel)}_range`,
    description: `Set the lowest and highest ${rangeLabel.toLowerCase()}.`,
    inputSchema: {
      type: 'object',
      properties: {
        low: { type: 'number', minimum: Number(input.min), maximum: Number(input.max) },
        high: { type: 'number', minimum: Number(input.min), maximum: Number(input.max) },
      },
      required: ['low', 'high'],
    },
    execute: async ({ low, high }) => {
      if (low > high) return 'The lowest value cannot be above the highest.';
      range.values = [low, high];
      input.dispatchEvent(new Event('change', { bubbles: true }));
      return `${rangeLabel}: ${range.values.join(' to ')}`;
    },
  }, opts);

A toggle key

A toggle key is a button with aria-pressed. Its name is its aria-label, or its text when it has no label. toggleKey(key, on) latches or releases it, announces the change the same way a press does, and returns the new state.

  const mute = document.querySelector('.tui-toggle-key');
  const muteLabel = mute.getAttribute('aria-label') ?? mute.textContent.trim();   // "Mute"
  await mc.registerTool({
    name: `set_${slug(muteLabel)}`,
    description: `Turn ${muteLabel.toLowerCase()} on or off.`,
    inputSchema: { type: 'object', properties: { on: { type: 'boolean' } }, required: ['on'] },
    execute: async ({ on }) => `${muteLabel} is ${toggleKey(mute, on) ? 'on' : 'off'}.`,
  }, opts);

The commit key, behind the alert dialog

Anything that pays, deploys, deletes or sends must ask first. The tool below opens the kit's alert dialog with confirmDialog(), which answers with a promise, and only then runs the work on the key with run(). The tool is also marked consequentialHint: true, so the browser or the agent can ask the person as well.

  const deploy = document.querySelector('tui-commit');
  const deployLabel = deploy.key.querySelector('[data-for="idle"]').textContent.trim();   // "Deploy to production"
  await mc.registerTool({
    name: slug(deployLabel),
    description: `${deployLabel}. Asks the person first.`,
    inputSchema: { type: 'object', properties: {} },
    annotations: { consequentialHint: true },
    execute: async () => {
      const yes = await confirmDialog({ title: `${deployLabel}?`, body: 'This cannot be undone.', confirm: 'Deploy' });
      if (!yes) return 'The person said no.';
      await deploy.run(() => startDeploy());           // your own function that returns a promise
      return 'Done.';
    },
  }, opts);
}

Do not rely on the key's data-guard cover for this. It only works on clicks, and run() never checks it, so the dialog has to be asked by the tool.

The one limit

The dialog always shows, and the browser has its own prompt as a second guard. But the page cannot tell whether a person or the agent pressed Confirm. Treat the dialog as a question put to whoever is driving the browser, not as proof that a person answered. For anything that cannot be undone, keep the check on your server as well.

Keep tools short

Chrome's guide suggests under 500 characters for a description and 150 for each input. Mark a tool that returns other people's words, such as comments or a table of user data, with untrustedContentHint: true.

Sources: Chrome's WebMCP overview, the imperative API, building secure tools and Chrome Status.