Skip to content

webfuse-com/WebMCP-polyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebMCP polyfill

WebMCP Draft (23 April 2026) compliant API polyfill.

  • ModelContext
  • ModelContextClient
  • navigator.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

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

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

The WebMCP polyfill bridges web applications and models

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.

About

WebMCP polyfill

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors