npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@w3c/webmcp-polyfill

v0.1.0

Published

A polyfill for WebMCP

Downloads

8,763

Readme

WebMCP polyfill

A polyfill for WebMCP, the API that lets web pages expose tools to browser agents through document.modelContext. It follows the WebMCP draft from the Web Machine Learning Community Group, uses types from webmcp-types, and has no runtime JavaScript dependencies.

WebMCP is a Community Group draft, not a W3C Standard, and it is still changing. Expect this package to change with it.

This project is part of the W3C Open Source Program pilot. See its project page for what that means.

Install

npm install @w3c/webmcp-polyfill

Usage

The API only exists in secure contexts, so serve your page over HTTPS or from localhost.

Load the polyfill before you register tools:

import "@w3c/webmcp-polyfill/auto";

const context = document.modelContext;
if (!context) {
  throw new Error("WebMCP requires a secure browser context");
}

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 pageTitleTool = tools.find((tool) => tool.name === "page-title");
if (!pageTitleTool) {
  throw new Error("The page-title tool is unavailable");
}

const result = await context.executeTool(pageTitleTool);
console.log(result);

// Remove the tool when it is no longer needed.
registration.abort();

If you'd rather install it yourself, call installWebMCP() from @w3c/webmcp-polyfill. Calling it more than once is fine. Neither entry point replaces a native document.modelContext, even a partial one.

Script tag

The package also ships a standalone build at dist/polyfill.js. Load it before your app:

<script src="/assets/polyfill.js"></script>
<script src="/assets/app.js"></script>

It installs document.modelContext as soon as it runs.

Next.js

In Next.js 15.3+, add this to instrumentation-client.ts beside app (or src/instrumentation-client.ts beside src/app):

import "@w3c/webmcp-polyfill/auto";

Next.js runs client instrumentation before hydration. A Server Component import alone won't install the polyfill in the browser.

Both entry points are SSR-safe: installation does nothing without a document. Your pages can stay server-rendered; WebMCP runs in the browser.

The package needs no "use client" directive. Use it on your Client Components and access document.modelContext in effects or event handlers. Pass an AbortSignal when registering in an effect, then abort it during cleanup.

Frames

Load the polyfill in each frame. Same-origin tools are visible by default, including those in parents and siblings. Pass the discovered descriptor to executeTool() so names shared by different frames reach the correct owner.

For cross-origin tools, delegate the tools permission on the iframe, register the tool with exposedTo: [callerOrigin], and discover it with getTools({ fromOrigins: [toolOrigin] }). Same-origin tools are still included in that result.

<iframe src="https://tools.example/app" allow="tools https://tools.example"></iframe>

Initial discovery waits up to 500 ms for existing frames. Requests use MessageChannel after checking the peer's source and origin; callbacks run in their owning frame. Cancellation preserves the caller's reason and sends the callback a default AbortError.

Implementation status

The polyfill targets [email protected] and covers registration, discovery, execution, cancellation and toolchange, including frame exposure and origin filtering. Declarative forms and the toolactivated/toolcancel events are not implemented yet. Talking to an actual browser agent needs support from the browser itself.

Native contexts do not join the polyfill's channels. TESTING.md lists the known differences from the draft, the test commands, and the spec and WPT revisions we test against.

executeTool() accepts an object and returns a JSON-serialized result. Omitted or undefined input defaults to a fresh empty object. Callbacks must validate their inputs; schema inference provides TypeScript checks only.

Breaking API changes ship with notes: in minor releases while the version is 0.x, in majors after 1.0.

Contributing

src/ holds the polyfill, tests/ the browser and package checks, and wpt/ the web-platform-tests runner, pin, and expectations. To work on it, use Node.js 24 and pnpm:

pnpm install
pnpm test

Spec questions belong in the WebMCP repository. See CONTRIBUTING.md for the contributor agreement and GOVERNANCE.md for how the project is run.

License

Apache-2.0 © 2026 World Wide Web Consortium