Canonical surface
New code usesdocument.modelContext.
Register a tool with abort cleanup
registerTool() returns Promise<void>, and tool cleanup is tied to the
optional AbortSignal passed at registration time. Invalid descriptors and
duplicate names reject the returned promise, so await registration or handle
its rejection.
ModelContextTool has the following fields:
Registration options are
signal, which unregisters the tool when aborted,
and exposedTo, an array of origins in the current document tree to which the
tool may be exposed. getTools() accepts fromOrigins to include tools from
specified origins; without it, discovery is same-origin.
getTools() returns RegisteredTool values. They contain name, optional
title, description, serialized inputSchema, window, origin, and
optional annotations. They do not expose the original execute callback.
The API is available only in secure contexts. The tools Permissions Policy
defaults to self; cross-origin discovery still requires explicit exposure and
policy delegation.
Chrome execution extension
Chrome’s current preview addsexecuteTool(tool, inputJson, options?). It is
not part of the strict WebMCP Community Group draft, so feature-detect
it:
Execute a discovered tool in Chrome
getTools(), a JSON object or
array string, and optional abort options. It resolves to a JSON string or
null.
Compatibility
navigator.modelContextis a deprecated compatibility alias. Current Chrome exposesdocument.modelContextonly.navigator.modelContextTestingis a removed Chromium preview API retained only by older runtimes and MCP-B/polyfill compatibility shims.listTools(), prompt and resource registration,mcpServer, and transports belong to MCP-B runtimes. Sampling and elicitation remain protocol-specific APIs on the composed official MCP server, notdocument.modelContextmethods.outputSchemais not part of the current W3C/Chrome WebMCP tool dictionary. MCP-B packages expose it as helper metadata for type inference, structured MCP responses, and polyfill/runtime adapters.
@mcp-b/webmcp-polyfill for the
portable strict runtime.