Skip to main content
@mcp-b/webmcp-polyfill bundles the upstream webmachinelearning/webmcp-polyfill at revision 439c6c341f1c632c63498ba206e2bd8471cb8efb. It installs the standard document.modelContext runtime when the browser does not provide one. The WebMCP draft and upstream package define the core API. This package temporarily adds declarative tools and their SubmitEvent extensions until upstream supports them. Use @mcp-b/global for transports, prompts, resources, and MCP outputSchema support.

Package entries

The standalone bundle installs document.modelContext automatically:

Minimal example

installWebMCP()

Call the installer before registering tools. Installation is idempotent and preserves an existing native context. It does nothing when the browser document is unavailable, on an insecure page, or below the browser baseline. Importing the ESM entry does not install the runtime as a side effect. The script bundle exposes the installer as WebMCPPolyfill.installWebMCP.

Core runtime

The installed document.modelContext implementation comes from the pinned upstream package. Use the upstream API reference for method signatures and behavior. The polyfill follows the current object-input executeTool() shape and supports registration cancellation through AbortSignal. The package does not provide:
  • cleanupWebMCPPolyfill() or another uninstall operation.
  • A navigator.modelContext alias or navigator.modelContextTesting shim.
  • MCP outputSchema metadata.
  • MCP prompts, resources, or transports.
For MCP features, use @mcp-b/global. The upstream context and the declarative layer remain installed for the lifetime of the document. MCP-B schema conversion and response helpers are exported by the @mcp-b/webmcp-ts-sdk/schema adapter. The polyfill’s document.modelContext.registerTool() follows WebMCP and does not validate invocation arguments.

Declarative tools

The declarative layer registers a tool for each form with toolname and tooldescription in the document and its open shadow roots. tooltitle sets the tool title. The input schema comes from the form’s named controls; toolparamdescription on a control or its fieldset describes the parameter.
An invocation fills the controls and dispatches input and change events. Without toolautosubmit, it focuses the first enabled submit button and waits for the user to submit; a form with no submit button rejects. With toolautosubmit, it runs constraint validation and calls requestSubmit() before toolactivated fires. The layer does not emulate the :tool-form-active and :tool-submit-active pseudo-classes and skips closed shadow roots, file inputs, and form-associated custom elements. The declarative API page links the proposal and Chrome sources.

Browser baseline

installWebMCP() installs only when the engine provides every API the vendored core calls. Otherwise it returns without defining document.modelContext, so if (!document.modelContext) remains a valid feature check. The resulting floor is Chrome 126, Firefox 126, and Safari 18.

WebMCP draft

Read the current Community Group report.