@mcp-b/webmcp-polyfill
Strict WebMCP core runtime polyfill for document.modelContext (with deprecated navigator.modelContext alias)
Last updated 3 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @mcp-b/webmcp-polyfill 
SYNC missed versions from official npm registry.

@mcp-b/webmcp-polyfill

This package is a temporary compatibility distribution of the upstream WebMCP polyfill, distributed under the existing MCP-B package name with vendored upstream source.

This package will eventually be removed. There is no removal date yet. Sites using declarative tools should keep this package until the upstream polyfill supports them. For other sites, follow the upstream installation instructions when its distribution is available.

Until then, this package bundles upstream revision 6bf6c57bbaf3d1173d7737cfb79572632d9b7871. It installs the standard document.modelContext API when the browser does not provide one, plus a temporary declarative tools layer. The upstream implementation and types are the source of truth for the core runtime. Use @mcp-b/global for transports, prompts, resources, or MCP outputSchema support; MCP-B schema helpers live in @mcp-b/webmcp-ts-sdk/schema.

The package reference documents the installer, the declarative layer, and the browser baseline.

Use the compatibility package

pnpm add @mcp-b/webmcp-polyfill

Install the polyfill

Call installWebMCP() before your app registers tools:

import { installWebMCP } from '@mcp-b/webmcp-polyfill';

installWebMCP();

const context = document.modelContext;
if (!context) throw new Error('WebMCP is unavailable');

The call is idempotent and preserves an existing native context. It does nothing when no browser document is available, on an insecure page, or on engines older than Chrome 126, Firefox 126, or Safari 18, so if (!document.modelContext) remains a valid feature check. The upstream runtime has no uninstall operation and does not provide the deprecated navigator.modelContext alias.

For a script tag, load the IIFE before registering tools:

<script src="https://unpkg.com/@mcp-b/webmcp-polyfill@6/dist/index.iife.js"></script>

The IIFE calls installWebMCP() automatically and exposes it as WebMCPPolyfill.installWebMCP.

Register a tool

Tool registrations follow the upstream WebMCP API. Pass an AbortSignal when the registration has a lifecycle:

const registration = new AbortController();

await context.registerTool(
  {
    name: 'page-title',
    description: 'Get the title of this page',
    execute() {
      return { title: document.title };
    },
  },
  { signal: registration.signal }
);

const tools = await context.getTools();
const tool = tools.find((item) => item.name === 'page-title');
if (tool) {
  const result = await context.executeTool(tool);
  console.log(result);
}

registration.abort();

See the WebMCP draft and the upstream polyfill for the standard API and implementation details.

Declare a tool in HTML

The declarative layer registers a tool for each form with toolname and tooldescription in the document and its open shadow roots. The input schema comes from the form's named controls.

<form toolname="search_catalog" tooldescription="Search the product catalog" toolautosubmit>
  <input name="query" required toolparamdescription="Words to match" />
  <button type="submit">Search</button>
</form>

<script>
  document.querySelector('form').addEventListener('submit', (event) => {
    if (!event.agentInvoked) return;

    event.preventDefault();
    event.respondWith(Promise.resolve({ matches: [] }));
  });
</script>

An invocation fills the controls and either submits the form (toolautosubmit) or focuses its submit button for the user. The declarative tools reference covers results, lifecycle events, cancellation, failures, and native browser hooks.

License

The package includes the upstream polyfill's MIT license notice.

Current Tags

  • 6.0.0-beta.20261001010549                                ...           beta (2 months ago)
  • 0.1.0-canary.20260214192802                                ...           canary (9 months ago)
  • 6.2.0                                ...           latest (18 days ago)

49 Versions

  • 6.2.0                                ...           18 days ago
  • 6.1.0                                ...           18 days ago
  • 6.0.3                                ...           a month ago
  • 6.0.2                                ...           a month ago
  • 6.0.1                                ...           2 months ago
  • 6.0.0                                ...           2 months ago
  • 6.0.0-beta.20261001010549                                ...           2 months ago
  • 5.1.0                                ...           3 months ago
  • 5.0.3                                ...           3 months ago
  • 5.0.1                                ...           3 months ago
  • 5.0.0                                ...           3 months ago
  • 4.1.0-beta.20260702224704                                ...           5 months ago
  • 4.0.0                                ...           5 months ago
  • 4.0.0-beta.20260702180822                                ...           5 months ago
  • 4.0.0-beta.20260702175639                                ...           5 months ago
  • 4.0.0-beta.20260702174111                                ...           5 months ago
  • 4.0.0-beta.20260702173007                                ...           5 months ago
  • 3.0.0-beta.20260702171253                                ...           5 months ago
  • 3.0.0                                ...           6 months ago
  • 3.0.0-beta.20260529000441                                ...           6 months ago
  • 2.3.1-beta.20260528050333                                ...           6 months ago
  • 2.3.2                                ...           7 months ago
  • 2.3.1                                ...           7 months ago
  • 2.3.0                                ...           7 months ago
  • 0.0.0-beta-20260319163307                                ...           8 months ago
  • 0.0.0-beta-20260311230356                                ...           9 months ago
  • 0.0.0-beta-20260311225423                                ...           9 months ago
  • 0.0.0-beta-20260311225012                                ...           9 months ago
  • 2.2.0                                ...           9 months ago
  • 2.1.0                                ...           9 months ago
  • 2.0.13                                ...           9 months ago
  • 2.0.12                                ...           9 months ago
  • 2.0.11                                ...           9 months ago
  • 2.0.10                                ...           9 months ago
  • 2.0.9                                ...           9 months ago
  • 2.0.8                                ...           9 months ago
  • 2.0.7                                ...           9 months ago
  • 2.0.6                                ...           9 months ago
  • 2.0.5                                ...           9 months ago
  • 0.3.3                                ...           9 months ago
  • 0.3.2                                ...           9 months ago
  • 0.3.1                                ...           9 months ago
  • 0.3.0                                ...           9 months ago
  • 0.0.0-beta-20260221154800                                ...           9 months ago
  • 0.2.1                                ...           9 months ago
  • 0.2.0                                ...           9 months ago
  • 0.0.0-beta-20260216200013                                ...           9 months ago
  • 0.1.0-canary.20260214192802                                ...           9 months ago
  • 0.1.0                                ...           9 months ago
Downloads
Total 197
Today 0
This Week 99
This Month 197
Last Day 0
Last Week 89
Last Month 0
Dependencies (2)
Dev Dependencies (5)
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE