WebMCP Draft (23 April 2026) compliant API polyfill.
ModelContextModelContextClientnavigator.modelContext
<script src="https://cdn.jsdelivr.net/gh/webfuse-com/WebMCP-polyfill@main/dist/webmcp-polyfill.js"></script>npm install webfuse-com/WebMCP-polyfillimport { ModelContext, ModelContextClient } from "@webfuse-com/webmcp-polyfill";navigator.modelContext
.registerTool({
name: "get_products",
description: "List all products in the current page.",
annotations: { readOnlyHint: true },
execute: () => state.getProducts()
});
navigator.modelContext
.registerTool({
name: "add_product_to_cart",
description: "Add a product to the user's shopping cart.",
inputSchema: {
type: "object",
properties: { product_id: { type: "string" } },
required: [ "product_id" ]
},
execute: async ({ product_id }) => {
await state.cart.addToCart(product_id);
return {
ok: true,
product_id
};
}
});The experimental navigator.modelContextTesting global allows maintaining an AI agent queue right in the web page's script execution scope.
navigator.modelContextTesting: ModelContextTestinginterface RegisteredTool {
name: string;
title: string | null;
description: string;
inputSchema: string;
readOnlyHint: boolean;
untrustedContentHint: boolean;
}
interface ModelContextTesting extends EventTarget {
// List snapshot for each registered tool.
listTools(): RegisteredTool[];
// Invoke a registered tool.
executeTool(name: string, input?: object | string): Promise<unknown>;
// Listen for tool changes.
addEventListener(type: "toolchange", listener: (e: Event) => void): void;
}Use WebMCP tools through a browser automation framework (e.g., Playwright), including legacy browsers.
Use WebMCP tools from native browser extensions.
Reuse WebMCP tools for in-page script execution realms.