Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebMCP polyfill

WebMCP Draft (23 April 2026) compliant API polyfill.

  • ModelContext
  • ModelContextClient
  • document.modelContext

Integrate

Browser

<script src="https://cdn.jsdelivr.net/gh/webfuse-com/WebMCP-polyfill@main/dist/webmcp-polyfill.js"></script>

Module

npm install webfuse-com/WebMCP-polyfill
import { ModelContext, ModelContextClient } from "@webfuse-com/webmcp-polyfill";

Usage

document.modelContext
  .registerTool({
    name: "get_products",
    description: "List all products in the current page.",
    annotations: { readOnlyHint: true },
    execute: () => state.getProducts()
  });

document.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
      };
    }
  });

WebMCP Registry non-spec

The experimental navigator.modelContextTesting global allows maintaining an AI agent queue right in the web page's script execution scope.

navigator.modelContextTesting: ModelContextTesting
interface 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 Cases

Model-driven Browser Automation

Use WebMCP tools through a browser automation framework (e.g., Playwright), including legacy browsers.

First-Class Access from Browser Extensions

Use WebMCP tools from native browser extensions.

Web Application MCP Introspection

Reuse WebMCP tools for in-page script execution realms.

Releases

Contributors

Languages