{"name":"@mcp-b/webmcp-polyfill","version":"2.1.0","keywords":["webmcp","model-context","navigator-modelcontext","polyfill","browser"],"author":{"name":"Alex Nahas"},"license":"MIT","_id":"@mcp-b/webmcp-polyfill@2.1.0","maintainers":[{"name":"miguelspizza","email":"alexmnahas@gmail.com"}],"homepage":"https://docs.mcp-b.ai/packages/webmcp-polyfill","bugs":{"url":"https://github.com/WebMCP-org/npm-packages/issues"},"dist":{"shasum":"1233a2a855067ca92fc20194dbbdfb6c4093d784","tarball":"http://registry-npm.ywwl.com/@mcp-b/webmcp-polyfill/download/@mcp-b/webmcp-polyfill-2.1.0.tgz","fileCount":8,"integrity":"sha512-AKvdv49WRNvzrmgRo+3M3/RPriudc/fyfkRwaC6gaIpReleNUnRFe55W2DpTu9hiY8gdMDgIF4Qag7YrGR/JAQ==","signatures":[{"sig":"MEQCIDvLSYOP8OplMzGxlroH45ycLEQoIHjvP/QBS4WhlGdDAiAhSOZgehQ0oeXgCwcbBkEAEpk8sQe86PBHnP0OIqDCWQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":98753,"size":25586,"noattachment":false,"key":"/@mcp-b/webmcp-polyfill/-/@mcp-b/webmcp-polyfill-2.1.0.tgz"},"main":"./dist/index.js","type":"module","_from":"file:mcp-b-webmcp-polyfill-2.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","browser":"./dist/index.iife.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./iife":{"script":"./dist/index.iife.js","default":"./dist/index.iife.js"}},"scripts":{"lint":"biome lint --write .","test":"vitest run","build":"pnpm --filter @mcp-b/webmcp-types build && tsdown","check":"biome check --write .","clean":"rm -rf dist .turbo","format":"biome format --write .","typecheck":"pnpm --filter @mcp-b/webmcp-types build && tsc --noEmit && vitest run --typecheck --silent","publish:dry":"pnpm publish --access public --dry-run","publish:npm":"pnpm publish --access public","test:browser":"vitest run --config vitest.browser.config.ts --browser.headless","test:browser:ui":"vitest --config vitest.browser.config.ts --browser"},"_npmUser":{"name":"miguelspizza","email":"alexmnahas@gmail.com"},"_resolved":"/private/var/folders/5y/ysfq1x7s50lc168yy1gvvf4m0000gn/T/c2db85f2f435b1442b5d5542c3e04076/mcp-b-webmcp-polyfill-2.1.0.tgz","_integrity":"sha512-AKvdv49WRNvzrmgRo+3M3/RPriudc/fyfkRwaC6gaIpReleNUnRFe55W2DpTu9hiY8gdMDgIF4Qag7YrGR/JAQ==","repository":{"url":"git+https://github.com/WebMCP-org/npm-packages.git","type":"git","directory":"packages/webmcp-polyfill"},"_npmVersion":"11.4.2","description":"Strict WebMCP core runtime polyfill for navigator.modelContext","directories":{},"sideEffects":true,"_nodeVersion":"24.3.0","dependencies":{"@mcp-b/webmcp-types":"2.1.0","@cfworker/json-schema":"^4.1.1","@standard-schema/spec":"^1.1.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.15.10","vitest":"^4.0.18","happy-dom":"^20.0.0","playwright":"^1.58.0","typescript":"^5.8.3","@vitest/browser":"^4.0.18","@vitest/coverage-v8":"^4.0.18","@vitest/browser-playwright":"^4.0.18"},"_npmOperationalInternal":{"tmp":"tmp/webmcp-polyfill_2.1.0_1772858922761_0.9456517818932084","host":"s3://npm-registry-packages-npm-production"},"readme":"# @mcp-b/webmcp-polyfill\n\nThis package is a temporary compatibility distribution of the upstream\n[WebMCP polyfill](https://github.com/webmachinelearning/webmcp-polyfill), distributed\nunder the existing MCP-B package name with vendored upstream source.\n\n**This package will eventually be removed.** There is no removal date yet. Sites\nusing declarative tools should keep this package until the upstream polyfill\nsupports them. For other sites, follow the\n[upstream installation instructions](https://github.com/webmachinelearning/webmcp-polyfill#readme)\nwhen its distribution is available.\n\nUntil then, this package bundles upstream revision\n`6bf6c57bbaf3d1173d7737cfb79572632d9b7871`. It installs the standard\n`document.modelContext` API when the browser does not provide one, plus a\ntemporary declarative tools layer. The upstream implementation and types are the\nsource of truth for the core runtime. Use [`@mcp-b/global`](../global/README.md)\nfor transports, prompts, resources, or MCP `outputSchema` support; MCP-B schema\nhelpers live in `@mcp-b/webmcp-ts-sdk/schema`.\n\nThe [package reference](https://docs.mcp-b.ai/packages/webmcp-polyfill/reference)\ndocuments the installer, the declarative layer, and the browser baseline.\n\n## Use the compatibility package\n\n```bash\npnpm add @mcp-b/webmcp-polyfill\n```\n\n## Install the polyfill\n\nCall `installWebMCP()` before your app registers tools:\n\n```ts\nimport { installWebMCP } from '@mcp-b/webmcp-polyfill';\n\ninstallWebMCP();\n\nconst context = document.modelContext;\nif (!context) throw new Error('WebMCP is unavailable');\n```\n\nThe call is idempotent and preserves an existing native context. It does\nnothing when no browser document is available, on an insecure page, or on\nengines older than Chrome 126, Firefox 126, or Safari 18, so\n`if (!document.modelContext)` remains a valid feature check. The upstream\nruntime has no uninstall operation and does not provide the deprecated\n`navigator.modelContext` alias.\n\nFor a script tag, load the IIFE before registering tools:\n\n```html\n<script src=\"https://unpkg.com/@mcp-b/webmcp-polyfill@6/dist/index.iife.js\"></script>\n```\n\nThe IIFE calls `installWebMCP()` automatically and exposes it as\n`WebMCPPolyfill.installWebMCP`.\n\n## Register a tool\n\nTool registrations follow the upstream WebMCP API. Pass an `AbortSignal` when\nthe registration has a lifecycle:\n\n```ts\nconst registration = new AbortController();\n\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 tool = tools.find((item) => item.name === 'page-title');\nif (tool) {\n  const result = await context.executeTool(tool);\n  console.log(result);\n}\n\nregistration.abort();\n```\n\nSee the [WebMCP draft](https://webmachinelearning.github.io/webmcp/) and the\n[upstream polyfill](https://github.com/webmachinelearning/webmcp-polyfill) for\nthe standard API and implementation details.\n\n## Declare a tool in HTML\n\nThe declarative layer registers a tool for each form with `toolname` and\n`tooldescription` in the document and its open shadow roots. The input schema\ncomes from the form's named controls.\n\n```html\n<form toolname=\"search_catalog\" tooldescription=\"Search the product catalog\" toolautosubmit>\n  <input name=\"query\" required toolparamdescription=\"Words to match\" />\n  <button type=\"submit\">Search</button>\n</form>\n\n<script>\n  document.querySelector('form').addEventListener('submit', (event) => {\n    if (!event.agentInvoked) return;\n\n    event.preventDefault();\n    event.respondWith(Promise.resolve({ matches: [] }));\n  });\n</script>\n```\n\nAn invocation fills the controls and either submits the form (`toolautosubmit`)\nor focuses its submit button for the user. The\n[declarative tools reference](https://docs.mcp-b.ai/packages/webmcp-polyfill/reference#declarative-tools)\ncovers results, lifecycle events, cancellation, failures, and native browser\nhooks.\n\n## License\n\nThe package includes the upstream polyfill's MIT license notice.\n","publish_time":1772858922904,"_cnpm_publish_time":1772858922904,"dist-tags":{"beta":"6.0.0-beta.20261001010549","canary":"0.1.0-canary.20260214192802","latest":"6.2.0"}}