GitHub - webmachinelearning/webmcp: 🤖 WebMCP
Key Points
- 1WebMCP is a proposed web platform API that allows developers to expose client-side JavaScript functions and HTML forms as "tools" for direct ingestion and actuation by AI agents.
- 2By enabling in-page tool registration, the framework facilitates collaborative human-AI workflows, providing a more reliable and context-aware alternative to brittle DOM scraping or external backend integrations.
- 3The design prioritizes security and control through standard browser-mediated permissions, origin-based tool exposure, and a developer-friendly architecture that complements existing web technologies.
WebMCP is a proposed web platform API designed to bridge the gap between AI agents and web content by allowing developers to expose client-side JavaScript functions and HTML form elements as structured, discoverable "tools." Unlike traditional backend integrations (such as the standard Model Context Protocol), which communicate directly with server-side APIs, WebMCP operates within the browser, enabling agents to interact with web pages directly via the DOM and existing client-side application logic.
Core Methodology
The framework introduces thedocument.modelContext interface, which serves as the primary mechanism for imperative tool management. Developers register tools by providing a name, a natural language description, an inputSchema (defined in JSON Schema format), and an execute callback.- Registration and Lifecycle: Using
document.modelContext.registerTool(), developers define actions that the agent can discover and invoke. The API supports dynamic registration and unregistration via anAbortController, allowing tools to be added or removed based on the current page state, user authentication, or specific user workflows. - Execution Flow: When an agent invokes a tool, it transmits arguments that are validated against the defined
inputSchema. The browser mediates this call, triggering theexecutecallback. This function can then perform arbitrary client-side tasks, such as UI updates, fetching data viafetch(), or manipulating the DOM. The result is returned to the agent in a structured format, maintaining a cooperative loop between the human user, the agent, and the web interface. - Security and Access Control: The framework incorporates a
Permissions-Policymechanism (tools), enabling developers to explicitly manage agent access. By default, tools are restricted to the top-level origin. For complex scenarios involving iframes, theexposedToproperty allows granular control, enabling developers to share tools only with specific, trusted secure origins. - Declarative Integration: To lower the barrier to entry, WebMCP includes a declarative layer for standard HTML elements. This allows the browser to automatically synthesize tool definitions from existing markup, reducing the need for redundant boilerplate code.
Objectives and Differentiation
The primary goal of WebMCP is to prevent "UI disintermediation," ensuring that AI agents enhance the web experience rather than bypassing the browser entirely. By leveraging client-side code, WebMCP maintains shared state and authentication context, which are often lost in server-side integrations. While the protocol draws architectural inspiration from the Model Context Protocol (MCP)—utilizing similar concepts of tools and schemas—it is explicitly optimized for the browser’s constraints, including tab-level lifecycle management, origin isolation, and standard web security models.Key Technical Considerations
The proposal acknowledges the necessity for future development in several areas, including:- Multimodal Capabilities: Supporting binary media inputs/outputs and streams for more complex AI interactions.
- User Authority: Designing mechanisms for explicit user confirmation before sensitive tool execution, likely through native browser permission dialogues.
- Progress Tracking: Implementing mechanisms to signal status for long-running operations.
- Service Worker Integration: Extending the discovery and invocation of tools to background contexts, allowing for agents to interact with sites even when they are not currently in the foreground.