{"_id":"@w3c/webmcp-polyfill","_rev":"1758439","name":"@w3c/webmcp-polyfill","description":"A polyfill for WebMCP","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"deniak","email":"denis@w3.org"},{"name":"dontcallmedom","email":"dom@w3.org"},{"name":"tidoust","email":"fd@tidoust.net"},{"name":"vivienlacourba","email":"vivien@w3.org"},{"name":"kfranqueiro","email":"kenneth.franqueiro@gmail.com"}],"time":{"modified":"2026-11-23T05:11:44.000Z","created":"2026-11-03T08:02:41.471Z","0.1.1":"2026-11-16T23:38:50.211Z","0.1.0":"2026-11-03T08:03:36.987Z","0.0.0-stage":"2026-11-03T08:02:41.471Z"},"users":{},"repository":{"url":"git+https://github.com/w3c-oss/webmcp-polyfill.git","type":"git"},"versions":{"0.1.1":{"_id":"@w3c/webmcp-polyfill@0.1.1","bugs":{"url":"https://github.com/w3c-oss/webmcp-polyfill/issues"},"dist":{"shasum":"cc492d05fee4669cd3293eb4da4f60877be93af4","tarball":"http://registry-npm.ywwl.com/@w3c/webmcp-polyfill/download/@w3c/webmcp-polyfill-0.1.1.tgz","fileCount":12,"integrity":"sha512-oIVCnVLd8pEvf8dPoU1j5SizqMi01LDeg4He0gfDRr34Krq64FA8J6CBELFKVfrmF0C3OfXehFVAgDRFqQZ8LQ==","signatures":[{"sig":"MEYCIQDjmcVjS7SXgfrfm3chK5Q+3im71sb8BXttVn5dJFr4UAIhAKmNUa0EiKhL3gOh0R//KaT++lqCxLTgtfWViXrhv6i0","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGfUQe3VxSCi3tVTJAXY+CqovW19xMqdmN/RX6r1Hu/eAiBVVCeFKr3j6ccUnk90JKiqmA8vzFEfctT6+LZRycZFjA=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@w3c%2fwebmcp-polyfill@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":95329,"size":26760,"noattachment":false,"key":"/@w3c/webmcp-polyfill/-/@w3c/webmcp-polyfill-0.1.1.tgz"},"name":"@w3c/webmcp-polyfill","pnpm":{"onlyBuiltDependencies":[]},"type":"module","types":"./dist/index.d.ts","exports":{".":"./dist/index.js","./auto":"./dist/auto.js"},"gitHead":"4c015623254b3a64d28b7c00b81a1672e3b1b5ab","license":"Apache-2.0","scripts":{"lint":"oxlint --deny-warnings","test":"pnpm lint && pnpm build && pnpm typecheck && playwright test","build":"tsc && esbuild src/auto.ts --bundle --format=iife --target=es2022 --minify --legal-comments=inline --outfile=dist/polyfill.js","prepack":"pnpm build","test:wpt":"pnpm build && node wpt/run.ts","typecheck":"tsc -p tsconfig.test.json","test:package":"node tests/package.test.ts"},"version":"0.1.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"400151c6-3b44-4d39-90ad-e981cb59d7bb"}},"homepage":"https://github.com/w3c-oss/webmcp-polyfill#readme","repository":{"url":"git+https://github.com/w3c-oss/webmcp-polyfill.git","type":"git"},"_npmVersion":"11.19.1","description":"A polyfill for WebMCP","directories":{},"maintainers":[{"name":"deniak","email":"denis@w3.org"},{"name":"dontcallmedom","email":"dom@w3.org"},{"name":"tidoust","email":"fd@tidoust.net"},{"name":"vivienlacourba","email":"vivien@w3.org"},{"name":"kfranqueiro","email":"kenneth.franqueiro@gmail.com"}],"sideEffects":["./dist/auto.js"],"_nodeVersion":"24.22.2","dependencies":{"webmcp-types":"^0.1.11"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.14.0","devDependencies":{"oxlint":"1.82.0","esbuild":"^0.25.0","typescript":"^5.9.0","@types/node":"^24.13.4","@playwright/test":"^1.55.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/webmcp-polyfill_0.1.1_1794872330139_0.8578565581322427"},"publish_time":1794872330211,"_cnpm_publish_time":1794872330211},"0.1.0":{"_id":"@w3c/webmcp-polyfill@0.1.0","bugs":{"url":"https://github.com/w3c-oss/webmcp-polyfill/issues"},"dist":{"shasum":"9e6707aaed69131f327dca3e70309e649952bec9","tarball":"http://registry-npm.ywwl.com/@w3c/webmcp-polyfill/download/@w3c/webmcp-polyfill-0.1.0.tgz","fileCount":10,"integrity":"sha512-FNzmob4B72T9cHDVODskyFjNi0JaZgcD1U0eFmuc2J4o3Lr5k1xabZ5rjw1AuvzgvdxRfvNr9FHUP9yG1s/StA==","signatures":[{"sig":"MEUCIGWhc8vbsrYRWXwWjKeKCmmvba6NTSYeyPyzSqV+atPnAiEAlFH16f4qZskikNC/ZMnW6Hv+HxnSYo3MjBZdWYLgzvU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFK8DuEpGHsXBfPyGgnIBfisjwpySB5VMBJzM1NO7T7BAiEA1X2ta1YFbAUghO/q9m0opCZBV/o6u+qSdY18PVWEfBM="}],"unpackedSize":81178,"size":23284,"noattachment":false,"key":"/@w3c/webmcp-polyfill/-/@w3c/webmcp-polyfill-0.1.0.tgz"},"name":"@w3c/webmcp-polyfill","type":"module","_from":"file:w3c-webmcp-polyfill-0.1.0.tgz","types":"./dist/index.d.ts","exports":{".":"./dist/index.js","./auto":"./dist/auto.js"},"license":"Apache-2.0","scripts":{"lint":"oxlint --deny-warnings","test":"pnpm lint && pnpm build && pnpm typecheck && playwright test","build":"tsc && esbuild src/auto.ts --bundle --format=iife --target=es2022 --minify --legal-comments=inline --outfile=dist/polyfill.js","test:wpt":"pnpm build && node wpt/run.ts","typecheck":"tsc -p tsconfig.test.json","test:package":"node tests/package.test.ts"},"version":"0.1.0","_npmUser":{"name":"tidoust","email":"fd@tidoust.net"},"homepage":"https://github.com/w3c-oss/webmcp-polyfill#readme","_resolved":"/home/tidoust/docs.w3.org/w3c-webmcp-polyfill-0.1.0.tgz","_integrity":"sha512-FNzmob4B72T9cHDVODskyFjNi0JaZgcD1U0eFmuc2J4o3Lr5k1xabZ5rjw1AuvzgvdxRfvNr9FHUP9yG1s/StA==","repository":{"url":"git+https://github.com/w3c-oss/webmcp-polyfill.git","type":"git"},"_npmVersion":"11.17.0","description":"A polyfill for WebMCP","directories":{},"maintainers":[{"name":"deniak","email":"denis@w3.org"},{"name":"dontcallmedom","email":"dom@w3.org"},{"name":"tidoust","email":"fd@tidoust.net"},{"name":"vivienlacourba","email":"vivien@w3.org"},{"name":"kfranqueiro","email":"kenneth.franqueiro@gmail.com"}],"sideEffects":["./dist/auto.js"],"_nodeVersion":"24.14.1","dependencies":{"webmcp-types":"^0.1.9"},"_hasShrinkwrap":false,"devDependencies":{"oxlint":"1.82.0","esbuild":"^0.25.0","typescript":"^5.9.0","@types/node":"^24.13.4","@playwright/test":"^1.55.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/webmcp-polyfill_0.1.0_1793693016894_0.6945288109570729"},"publish_time":1793693016987,"_cnpm_publish_time":1793693016987},"0.0.0-stage":{"name":"@w3c/webmcp-polyfill","version":"0.0.0-stage","_id":"@w3c/webmcp-polyfill@0.0.0-stage","stub":true,"maintainers":[{"name":"tidoust","email":"fd@tidoust.net"}],"dist":{"shasum":"89ce7c467992a311f532ab1ad566af234564b85c","tarball":"http://registry-npm.ywwl.com/@w3c/webmcp-polyfill/download/@w3c/webmcp-polyfill-0.0.0-stage.tgz","fileCount":2,"integrity":"sha512-nKmijD0633YmRniB9tjPnkg1rt+z9Dy0kDG9JWM9n4nFNMmDeqjLg8Ees9yQTuHkdnFEzdnaiwlM3nJ1mDfYuA==","signatures":[{"sig":"MEUCIQCx3H+b02dVuKEVEeFW7sfJnRnL+k0A85roC0dGkuIhTQIgQ6gOHv//iuC93w7DeZwpDdG3iGMFLQH57J6gGddIIVo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":342,"size":372,"noattachment":false,"key":"/@w3c/webmcp-polyfill/-/@w3c/webmcp-polyfill-0.0.0-stage.tgz"},"_npmUser":{"name":"tidoust","email":"fd@tidoust.net"},"description":"Temporary package placeholder for staged publishing","directories":{},"publish_time":1793692961471,"_cnpm_publish_time":1793692961471}},"readme":"# WebMCP polyfill\n\nA polyfill for [WebMCP](https://webmachinelearning.github.io/webmcp/), the API that lets web pages expose tools to browser agents through `document.modelContext`. It follows the [WebMCP draft](https://webmachinelearning.github.io/webmcp/) from the [Web Machine Learning Community Group](https://www.w3.org/groups/cg/webmachinelearning/), uses types from [webmcp-types](https://github.com/webmachinelearning/webmcp-types), and has no runtime JavaScript dependencies.\n\nWebMCP is a Community Group draft, not a W3C Standard, and it is still changing. Expect this package to change with it.\n\nThis project is part of the [W3C Open Source Program](https://github.com/w3c-oss/open-source-program) pilot. See its [project page](https://github.com/w3c-oss/open-source-program/blob/main/projects/webmcp-polyfill/README.md) for what that means.\n\n## Install\n\n```sh\nnpm install @w3c/webmcp-polyfill\n```\n\n## Usage\n\nThe API only exists in secure contexts, so serve your page over HTTPS or from localhost.\n\nLoad the polyfill before you register tools:\n\n```ts\nimport \"@w3c/webmcp-polyfill/auto\";\n\nconst context = document.modelContext;\nif (!context) {\n  throw new Error(\"WebMCP requires a secure browser context\");\n}\n\nconst registration = new AbortController();\nawait context.registerTool(\n  {\n    name: \"page-title\",\n    description: \"Get the title of this page\",\n    execute() {\n      return { title: document.title };\n    },\n  },\n  { signal: registration.signal },\n);\n\nconst tools = await context.getTools();\nconst pageTitleTool = tools.find((tool) => tool.name === \"page-title\");\nif (!pageTitleTool) {\n  throw new Error(\"The page-title tool is unavailable\");\n}\n\nconst result = await context.executeTool(pageTitleTool);\nconsole.log(result);\n\n// Remove the tool when it is no longer needed.\nregistration.abort();\n```\n\nIf 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.\n\n### Script tag\n\nThe package also ships a standalone build at `dist/polyfill.js`. Load it before your app:\n\n```html\n<script src=\"/assets/polyfill.js\"></script>\n<script src=\"/assets/app.js\"></script>\n```\n\nIt installs `document.modelContext` as soon as it runs.\n\n### Next.js\n\nIn Next.js 15.3+, add this to `instrumentation-client.ts` beside `app` (or `src/instrumentation-client.ts` beside `src/app`):\n\n```ts\nimport \"@w3c/webmcp-polyfill/auto\";\n```\n\nNext.js runs [client instrumentation](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client) before hydration. A Server Component import alone won't install the polyfill in the browser.\n\nBoth entry points are SSR-safe: installation does nothing without a document. Your pages can stay server-rendered; WebMCP runs in the browser.\n\nThe package needs no `\"use client\"` directive. Use it on your [Client Components](https://nextjs.org/docs/app/api-reference/directives/use-client) and access `document.modelContext` in effects or event handlers. Pass an `AbortSignal` when registering in an effect, then abort it during cleanup.\n\n## Frames\n\nLoad 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.\n\nFor 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.\n\n```html\n<iframe src=\"https://tools.example/app\" allow=\"tools https://tools.example\"></iframe>\n```\n\nInitial 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`.\n\n## Implementation status\n\nThe polyfill targets `webmcp-types@0.1.10` and covers registration, discovery, execution, cancellation, `toolchange` and the `toolactivated`/`toolcancel` events, including frame exposure and origin filtering. Declarative forms are not implemented yet. Talking to an actual browser agent needs support from the browser itself.\n\nNative contexts do not join the polyfill's channels. [TESTING.md](https://github.com/w3c-oss/webmcp-polyfill/blob/main/TESTING.md) lists the known differences from the draft, the test commands, and the spec and WPT revisions we test against.\n\n`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.\n\nA failed execution rejects with the draft's `DOMException` name, such as `NotFoundError` or `OperationError`, rather than the callback's own error.\n\nBreaking API changes ship with notes: in minor releases while the version is 0.x, in majors after 1.0.\n\n## Contributing\n\n`src/` holds the polyfill, `tests/` the browser and package checks, and `wpt/` the [web-platform-tests](https://github.com/web-platform-tests/wpt/tree/master/webmcp) runner, pin, and expectations. To work on it, use Node.js 24 and pnpm:\n\n```sh\npnpm install\npnpm test\n```\n\nSpec questions belong in the [WebMCP repository](https://github.com/webmachinelearning/webmcp/issues). See [CONTRIBUTING.md](CONTRIBUTING.md) for the contributor agreement and [GOVERNANCE.md](GOVERNANCE.md) for how the project is run.\n\n## License\n\n[Apache-2.0](LICENSE) © 2026 [World Wide Web Consortium](https://www.w3.org/)\n","_attachments":{},"homepage":"https://github.com/w3c-oss/webmcp-polyfill#readme","bugs":{"url":"https://github.com/w3c-oss/webmcp-polyfill/issues"},"license":"Apache-2.0"}