Skip to main content

WebMCP

WebMCP exposes the tools that a frame registers through the experimental WebMCP browser API, navigator.modelContext. It lists the tools and calls them.

Instances are accessed through frame.webmcp. page.webmcp is the instance of the main frame.

note

WebMCP is an experimental browser feature. Chromium enables it with the --enable-features=WebMCP launch argument, Firefox with the dom.modelcontext.enabled and dom.modelcontext.testing.enabled preferences. WebKit does not implement it.

Tool names, descriptions, input schemas and results are provided by the page, so treat them as untrusted input.


Methods​

call_tool​

Added in: v1.64 webMCP.call_tool

Calls a tool registered by the frame and returns its result. The result is whatever the tool's execute function resolved to, typically an object with a content array. A result with isError: true is returned as is. The method throws when the tool is not registered or its execute function throws.

Usage

web_mcp.call_tool(name)
web_mcp.call_tool(name, **kwargs)

Arguments

Returns


tools​

Added in: v1.64 webMCP.tools

Returns the tools currently registered by the frame. Throws if the browser was launched without WebMCP support, see the note above for the launch options that enable it.

page.webmcp covers the main frame only, child frames list their tools through their own frame.webmcp.

Usage

web_mcp.tools()
web_mcp.tools(**kwargs)

Arguments

Returns

  • List[Dict]#
    • name str

      Tool name, unique within the frame.

    • description str

      Tool description.

    • inputSchema Dict (optional)

      JSON Schema of the tool input, when the page provides one.

    • annotations Dict (optional)

      • readOnly bool (optional)

        The tool does not modify any state.

      • untrustedContent bool (optional)

        The tool output may contain third-party content.

      • consequential bool (optional)

        The tool takes a consequential action, such as placing an order.

      Hints the page provides about the tool.