How to Implement WebMCP on Your Site in 2026
WebMCP turns actions on your page into named, typed tools that an AI agent in the same tab can call directly. This page gives you the registerTool() code, the polyfill route and the Chrome 160 changes to reading tools back, all checked against the current W3C Community Group draft.
WebMCP (Web Model Context Protocol) is a browser API that lets a page register named tools, each with a JSON Schema for its inputs and a callback you wrote, so an AI agent in the same tab can invoke them instead of guessing at your UI. Tools run inside the user's existing session, so there is no separate server to stand up and no credentials to copy anywhere. The API lives at document.modelContext, and registerTool() is the only registration method in the current draft: the earlier declarative form attributes were dropped in October 2026.
Why WebMCP matters for AI visibility
A browser agent working a page without WebMCP reads the accessibility tree, guesses which control is the submit button, and retries when a click lands somewhere unexpected. Every re-render, hashed class name and A/B variant breaks that guess, and the failure is silent: the agent reports success on an action that never happened. A registered tool replaces the guess with a contract. The agent receives a name, a typed input schema and a return value, and your code decides what actually runs.
That makes WebMCP the one agent-facing surface where you set the vocabulary rather than a crawler. Adoption is still thin, so the cost of being early is small and the worst case is renaming a method later. For the background on where the protocol came from and how it sits next to Anthropic's MCP, the conceptual explanation lives here. The rest of this page is implementation.
Where the spec lives
WebMCP has changed shape several times since the first preview, and secondary write-ups go stale within weeks. Check these before you ship anything.
- WebMCP Draft Community Group Report - the normative text and WebIDL for
ModelContext,ModelContextTooland theDocumentpartial interface. Check the date on the report: PR #338 (8 October 2026) removed declarative tools, and PR #348 (merged around 19 November 2026) introduced theToolinterface. - webmachinelearning/webmcp explainer and issues - the explainer with the canonical
registerTool()example, and the open issues where field names get renamed. - PR #348: Introduce the Tool interface - the breaking change behind the Chrome 160 behaviour described below.
- Chrome for Developers: imperative API -
registerTool(),getTools(),executeTool(), thetoolchangeevent and AbortController-based unregistration. - Chrome for Developers: declarative API - deprecated, Chrome origin trial only. The form attribute API that was dropped from the W3C draft on 8 October 2026. Useful only to understand forms you need to migrate.
- Chrome for Developers: tool security - the annotation hints, the
exposedTooption for cross-origin sharing, and the character budgets agents apply to names, descriptions and output. - WebMCP-org/npm-packages - the
@mcp-b/webmcp-polyfillruntime and@mcp-b/webmcp-typesdeclarations, tested against the upstream web platform tests.
Three ways to implement WebMCP
All three go through registerTool(). The first wraps a form you already have, which suits content sites and server-rendered apps. The second registers stateful tools, which is what you need when the set of available actions depends on application state. The third runs the same code in browsers with no native implementation, which is how you ship to real traffic while the origin trials run.
Wrap an existing form in a registered tool
Start with the forms you already have. If a form has labelled, named controls, its fields map almost one to one onto a JSON Schema, and the function your submit handler calls becomes the tool's execute. The form itself stays an ordinary form for people.
// ES module. The form keeps working for people as before.
const form = document.querySelector('#catalogue-search');
if ('modelContext' in document && form) {
await document.modelContext.registerTool({
name: 'search_catalogue',
description: 'Search the product catalogue by keyword and category. Returns up to 10 products.',
inputSchema: {
type: 'object',
properties: {
q: { type: 'string', description: 'Words to match against product titles and descriptions.' },
category: {
type: 'string',
enum: ['all', 'tents', 'sleeping-bags'],
description: 'Restrict results to one category.'
}
},
required: ['q'],
additionalProperties: false
},
annotations: { readOnlyHint: true },
async execute({ q, category = 'all' }) {
// Reuse the function the form's submit handler already calls.
const results = await runSearch({ q, category });
return results.slice(0, 10).map(({ title, url, price }) => ({ title, url, price }));
}
});
}
What this does: the agent sees a search_catalogue tool with a q string and a category enum, and gets structured results back without the page navigating. Because the tool is registered the standard way, Chrome, ChatGPT's browser and the polyfill all see it. Each parameter is described inside the schema, which is what the Lighthouse 13.6 WebMCP schemas audit and Glippy look for.
Register a stateful tool with the imperative API
Reach for this when the tool is not a form: cart mutations, filters, canvas operations, anything where the available actions change as the user moves through the app. Registration is scoped to an AbortSignal, which is how you take a tool away again.
// ES module, loaded on product pages only.
if ('modelContext' in document) {
const controller = new AbortController();
await document.modelContext.registerTool(
{
name: 'add_to_cart',
title: 'Add to cart',
description: 'Add a product to the shopping cart. Returns the new cart total.',
inputSchema: {
type: 'object',
properties: {
sku: { type: 'string', description: 'Product SKU shown on the product page.' },
quantity: { type: 'integer', minimum: 1, description: 'How many units to add.' }
},
required: ['sku'],
additionalProperties: false
},
annotations: { readOnlyHint: false, untrustedContentHint: false },
async execute({ sku, quantity = 1 }, { signal }) {
const line = await cart.add(sku, quantity, { signal });
return `Added ${quantity} x ${sku}. Cart holds ${line.count} items, total ${line.total}.`;
}
},
{ signal: controller.signal }
);
// Leaving the product view removes the tool without killing work in flight.
router.on('leave', () => controller.abort());
}
What this does: the agent gets one unambiguous action with typed arguments, and the confirmation string tells it what changed so it does not have to re-read the page to verify. Aborting the controller fires a toolchange notification, so the agent stops offering an action that no longer exists.
Ship to every browser with the polyfill
Native WebMCP is Chromium only and still gated behind a flag or an origin trial, and no other engine implements it. The polyfill installs document.modelContext only when the browser has none, so one code path covers native and non-native visitors.
// npm install @mcp-b/webmcp-polyfill
// npm install -D @mcp-b/webmcp-types
import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
// Idempotent: it never replaces a native document.modelContext.
initializeWebMCPPolyfill();
export async function registerArticleTools(article) {
if (!('modelContext' in document)) return () => {};
const controller = new AbortController();
await document.modelContext.registerTool(
{
name: 'get_article_summary',
description: 'Return the title, canonical URL and summary of the article on screen.',
inputSchema: { type: 'object', properties: {} },
annotations: { readOnlyHint: true, untrustedContentHint: true },
execute: async () => ({
title: article.title,
canonical: document.querySelector('link[rel="canonical"]')?.href,
summary: article.summary
})
},
{ signal: controller.signal }
);
return () => controller.abort();
}
What this does: visitors on a Chromium build with WebMCP enabled use the native implementation; everyone else gets the polyfill, which runs the same registerTool() calls from examples 01 and 02. Cross-document features such as non-empty exposedTo and fromOrigins reject under the polyfill, so keep those paths behind a native check.
Deprecated, Chrome origin trial only: declarative form tools
Earlier drafts let a form declare a tool with HTML attributes: toolname and tooldescription on the form, toolparamdescription on its controls, and optionally toolautosubmit. The W3C draft dropped this on 8 October 2026 (PR #338). ChatGPT's browser does not support it, and only Chrome's origin trial still reads the attributes.
If your forms already carry these attributes: register the same tools with registerTool() as in example 01, reusing the toolname as the tool name, the tooldescription as its description and each toolparamdescription as the matching property's description. The leftover attributes do nothing for people, so you can remove them once the registered tool is live. Glippy lists these forms with a migration warning and gives them no points.
Implementation guidelines
These are the things that break WebMCP in production rather than in a demo.
- Tie every registration to an AbortController. Register a tool when the action becomes possible and abort the signal when it stops being possible. A listed tool that fails on call is worse than no tool, because the agent has already told the user it will work.
- Stay inside the character budgets. Chrome's guidance is roughly 500 characters per tool description, 150 per parameter description, 30 for a name, and 1.5K for tool output. Longer strings get truncated or trip agent guardrails, and the agent silently drops the tool.
- Do not opt out of origin isolation. WebMCP is only exposed in origin-isolated documents. Chromium has been origin-keyed by default since Chrome 106, so the usual cause of a missing
document.modelContextis a legacyOrigin-Agent-Cluster: ?0header kept around to makedocument.domainwritable. - Remember the tools Permissions Policy in iframes. The
toolspolicy defaults toself, so a widget you embed cross-origin registers nothing until the parent page addsallow="tools"to the iframe element. - Validate strictly in code, loosely in schema. Accept raw user input, declare enums and real types rather than opaque numeric IDs, and return a descriptive error string the model can correct against instead of throwing an opaque exception.
- Annotate honestly. Set
readOnlyHintonly on tools that change nothing, and setuntrustedContentHinton any tool returning user-generated or third-party content so the agent can treat the payload as data rather than instructions. - Keep the human path intact. Safari and Firefox have no implementation and Chromium support is still trial-gated, so every tool must map to something a person can still click. WebMCP is an addition to your UI, never a replacement for it.
Do this, not that
Do
- Name tools with a verb that says what happens on call, such as
create_booking, and keep it to 30 characters or fewer. - Feature-detect with
'modelContext' in documentbefore touching the API, so older browsers do not throw on load. - Give every tool a description and an input schema, and describe each parameter in its schema
description. Tools without them fail the Lighthouse 13.6 WebMCP schemas audit, and Glippy names them. - Keep the tool set small and non-overlapping; two tools that could both do the job make the agent pick wrong more often than a missing tool does.
Do not
- Do not write
navigator.modelContext. It is a deprecated compatibility alias fordocument.modelContextand Chromium logs a warning on first access. - Do not call
provideContext()orclearContext(). Both were dropped from the draft; the current surface isregisterTool()plus anAbortSignal. - Do not add new
toolnameattributes to forms. Declarative tools were dropped from the draft on 8 October 2026 and ChatGPT's browser ignores them. - Do not publish
/.well-known/webmcp.jsonand expect discovery. There is no manifest in the spec: tools are registered at runtime and the browser aggregates them. - Do not mark a destructive tool
readOnlyHint: trueto get agents to call it without confirming. That is the annotation agents use to decide when to skip asking the user.
Chrome 160 changes: the Tool interface
PR #348 ("Introduce the Tool interface"), merged into the spec around 19 November 2026, changes what you get when you read tools back. It ships in Chrome 160 (first in build 160.0.8173.0), and Chrome 160 reaches Stable on 5 January 2027. Pages that only call registerTool() do not need to change. Code that lists or runs tools does: agent extensions, test harnesses, debugging panels and audit scripts.
getTools()returnsToolinterface objects instead of plain dictionaries. Each one is bound to a single registration, so a tool re-registered under the same name is a different tool. This stops a tool being swapped silently between discovery and execution.executeTool()only accepts a tool obtained fromgetTools(). Objects you build yourself are rejected.tool.windowis renamedtool.source, and it isnullonce the document that registered the tool has gone.- An omitted
inputSchema,outputSchemaorannotationsreads asnull, notundefined. JSON.stringify(tool)returns{}, spreading a tool copies nothing, andstructuredClone(tool)throws. Read the properties you need one by one.- Separately, since 2 November 2026 a tool can declare an
outputSchema, with the same name and meaning as in MCP.
// Works on Chrome 160 and on older builds.
const tools = await document.modelContext.getTools();
const summary = tools.map((tool) => {
const source = 'source' in tool ? tool.source : tool.window;
return {
name: tool.name,
description: tool.description ?? '',
hasInputSchema: tool.inputSchema != null,
hasOutputSchema: tool.outputSchema != null,
// null: the registering document is gone. Another window: an iframe.
fromThisPage: source === window || source === undefined
};
});
// To run a tool later, keep the original object from getTools():
// executeTool() rejects copies.
Chrome has said more breaking changes will follow before a stabilised subset in early 2027, so re-test tool-reading code on Chrome Dev before each release. Glippy's Chrome extension reads tools this way, so its WebMCP checks keep working on Chrome 160.
How Glippy checks this
Glippy scores WebMCP under Agent Interactivity (category 10). Points come only from tools registered with registerTool(). The Chrome extension reads the live tool list through getTools() in the Chrome-160-safe way shown above and counts only tools the page itself registered, not tools from iframes or from documents that have gone. The MCP server and desktop app, which read the HTML rather than a live tab, look for scripts that call registerTool and for a loaded WebMCP polyfill or SDK. A separate check, the equivalent of the Lighthouse 13.6 WebMCP schemas audit, confirms that every registered tool has a description and an input schema and names the tools that do not.
Forms carrying toolname earn no points. Glippy lists them with a migration warning, together with their tool names and description coverage, so you can see what to port. It also reports form agent-readiness and whether your element IDs are stable rather than hashed per render, which is what an agent needs to reference a control twice. The category uses a bonus model at a low weight: a missing implementation is surfaced as a tip, and an imperfect one is a neutral warning, so neither drags your score down. The full breakdown is on the WebMCP Checker page.
Check your WebMCP setup
Glippy runs 240+ checks across 16 categories on any page, including Agent Interactivity (category 10). No sign-up required.
Frequently asked questions
WebMCP is Chromium only. Chrome shipped an early preview in Chrome 146 behind chrome://flags/#enable-webmcp-testing, and a Chrome origin trial has been running from Chrome 149, now extended to Chrome 162, so you can enable it for real users on a registered origin. Microsoft runs its own Edge origin trial. ChatGPT's built-in browser supports part of the API: tools registered with registerTool() in the top-level page, but no declarative form tools and no tools registered inside iframes. Safari and Firefox have no implementation, which is why the polyfill route matters if you want coverage today.
Yes. The declarative form attributes (toolname, tooldescription, toolparamdescription) were dropped from the W3C draft on 8 October 2026 in PR #338, so document.modelContext.registerTool() is the only standard way to register a tool. Chrome's origin trial still reads toolname forms, but ChatGPT's browser ignores them and Glippy gives them no points. The script can be small: wrap the function your form's submit handler already calls in a registered tool, as in the first example on this page.
No. The tool registration surface moved from Navigator to Document, so the canonical entry point is document.modelContext and navigator.modelContext survives only as a deprecated alias that logs a warning. Two earlier methods, provideContext() and clearContext(), were removed from the draft entirely and no shipping implementation exposes them. Current code uses document.modelContext.registerTool(tool, { signal }) and removes the tool by aborting that signal.
No, the two cover different lifetimes. An MCP server is persistent and headless: it exposes your data and actions to an agent anywhere, at any time, with its own authentication. WebMCP tools are ephemeral and bound to an open tab, running inside the session the user is already signed in to and acting on the state they can see. Most teams that do both keep business logic in MCP and use WebMCP to expose the in-page actions that only make sense with the user's current view.
Reviewed against the primary sources on . These standards move quickly, so check the linked specs before you ship.