webmcp-tool

WebMCP

Shipping WebMCP before the browsers catch up

A polyfill provides document.modelContext where the browser does not, a React hook ties registration to component lifecycle, and a relay bridges page tools to desktop clients. What each is for, and where the seams are.

Last reviewed 27 August 2026

Chrome carries WebMCP behind a flag or an origin trial. Edge is experimental. Firefox and Safari have committed to nothing. If you wait for universal support before writing a tool, you will write your first one in a year that has not been announced.

The MCP-B project fills the gap with a polyfill and a set of adapters. It is the practical route for anyone who wants tools in production this quarter.

The packages

PackageWhat it does
@mcp-b/webmcp-polyfillProvides document.modelContext where the browser has no native implementation
@mcp-b/webmcp-typesTypeScript types for the standard surface
usewebmcpReact hook that registers a tool and unregisters it on unmount
@mcp-b/globalOne import: polyfill plus an MCP server in the page
@mcp-b/webmcp-ts-sdkAdapter over the official MCP TypeScript SDK
@mcp-b/transportsPostMessage and WebSocket transports across contexts
@mcp-b/mcp-iframeBridges tools across iframe boundaries
@mcp-b/webmcp-local-relayExposes page tools to desktop MCP clients over WebSocket and stdio

The smallest useful setup

import "@mcp-b/webmcp-polyfill";

await document.modelContext.registerTool({
  name: "get_page_summary",
  description: "Return the title, canonical URL and section count of this page.",
  inputSchema: { type: "object", properties: {} },
  annotations: { readOnlyHint: true },
  execute: () => ({
    content: [{
      type: "text",
      text: JSON.stringify({
        title: document.title,
        url: location.href,
        sections: document.querySelectorAll("h2").length,
      }),
    }],
  }),
});

Import the polyfill before anything that touches document.modelContext. It is a no-op where the browser already implements the API, so there is no branch to maintain.

React: let the lifecycle own registration

Manual registration in an effect works, but the hook exists because getting cleanup wrong is the default outcome — and a stale tool is worse than a missing one. An agent calling add_to_cart from a page the user left is a bug your analytics will never show you.

import { useWebMCP } from "usewebmcp";

function ProductPage({ product }) {
  useWebMCP({
    name: "check_compatibility",
    description:
      `Check whether an accessory fits the ${product.name}. Returns a verdict and the reason.`,
    inputSchema: {
      type: "object",
      properties: { accessoryId: { type: "string", description: "Accessory SKU" } },
      required: ["accessoryId"],
    },
    annotations: { readOnlyHint: true },
    execute: async ({ accessoryId }) => checkFit(product.id, accessoryId),
  });

  return <ProductView product={product} />;
}

Where the seams are

  • A polyfill cannot create a consumer. It gives your code somewhere to register. Whether an agent reads that registration depends on the agent, and today the reliable one is the ChatGPT desktop app.
  • Pin your versions. The specification moved the API in July 2026. A polyfill pinned before that may still target navigator — see migration.
  • The relay crosses a trust boundary. @mcp-b/webmcp-local-relay exposes page tools to desktop clients over a local socket. That is powerful and it is exactly the kind of bridge to keep out of production builds.
  • Iframe bridging needs a policy. Cross-origin iframes need allow="tools" regardless of transport.
What we report

Our scanner treats a detected polyfill without an observed registration as partial, not a pass. The tooling being loaded is a signal of intent; a registered tool is a capability. It also scans same-origin bundles, because tools almost never live in the document itself.

Sources

Primary documents, checked on 27 August 2026

  1. docs.mcp-b.aiPackage list, polyfill, React hook, transports and local relay
  2. webmcp.devOpen-source JavaScript library for the same surface
  3. webmachinelearning.github.io/webmcpW3C Web Machine Learning Community Group draft — WebIDL, annotations, permissions policy
  4. developer.chrome.com/docs/ai/webmcpOrigin trial, flags, permissions policy directive

Keep reading

Check your own site against this

The Agent Readiness Score measures exactly what this article describes, and shows the evidence behind every finding.

Run the check →