WebMCP Tutorial: Building Agent-Ready Websites With Chrome New Standard
WebMCP (Web Model Context Protocol) is a new browser standard that lets websites declare their capabilities as structured tools that AI agents can call directly. Instead of forcing an AI to "read" and click through a visual interface, WebMCP turns the webpage itself into a clean, client-side API. This complete tutorial walks you through what WebMCP actually is, how to set up your environment, and build working integrations using both HTML-based and JavaScript-based approaches.
What You'll Learn:
- What WebMCP is and how it differs from standard MCP
- How to set up Chrome Canary and enable WebMCP flags
- Build declarative WebMCP tools with HTML form annotations
- Build imperative WebMCP tools with JavaScript API
- Handle agent invocation detection and safety patterns
- Test WebMCP implementations with Chrome DevTools and Model Context Tool Inspector
What Is WebMCP?
WebMCP (Web Model Context Protocol) is a new browser standard that lets websites declare their capabilities as structured tools that AI agents can call directly. Instead of forcing an AI to "read" and click through a visual interface, WebMCP turns the webpage itself into a clean, client-side API.
Let us think about what happens when an agent tries to book a flight on a travel site today. It has to figure out which field expects the departure city, guess whether the date format is MM/DD or YYYY-MM-DD, locate the search button, and hope the page does not reload into a layout it has never seen before. If the site could instead publish a tool called searchFlights with typed parameters, all of that guessing disappears.
WebMCP makes that possible. A site registers tools through a browser API called navigator.modelContext, where each tool comes with a name, a natural language description, and a JSON schema for its inputs and outputs. The agent discovers those tools, sends parameters that match the schema, and receives structured data in return.
WebMCP vs Standard MCP
| Feature | Standard MCP | WebMCP |
|---|---|---|
| Architecture | Backend server handles tool execution over JSON-RPC | Purely client-side, runs in browser tab |
| Tool Execution | Separate server process | In page JavaScript, shares user session |
| Discovery | MCP server connection | Agent visits page to discover tools |
| Infrastructure | Requires separate backend server | No backend needed, uses existing frontend JS |
WebMCP Key Features and Capabilities
Declarative API (HTML)
Add toolname and tooldescription attributes to form elements. Browser generates JSON schema from existing form structure automatically.
Imperative API (JavaScript)
Full programmatic control with navigator.modelContext.registerTool() for dynamic workflows and custom validation logic.
Dynamic Registration
Tools can appear and disappear as page state changes. Register login tool before auth, account tools after authentication.
CSS Pseudo-Classes
Visual feedback during agent interactions. :tool-form-active and :tool-submit-active show which form the agent is working on.
JSON Schemas
Every tool specifies types, enums, required fields, and parameter descriptions to prevent agents from inventing values.
No Backend Required
Tools run in page context, use same session as human user, need no additional infrastructure behind them.
Early Preview Note
WebMCP is still in early preview, available only in Chrome Canary behind a flag. The spec has already evolved, including removal of provideContext and clearContext methods in March 2026. Tool discoverability is limited to pages already visited. Check the Chrome documentation changelog before starting.
WebMCP Prerequisites and Environment Setup
Getting the environment right takes a few minutes, though the wrong Chrome version will waste considerably more time than that. Chrome Canary version 146.0.7672.0 or higher is required. The stable release, Beta, and Dev channels of Chrome do not ship with the WebMCP flag.
Download Chrome Canary
Download specifically from the Chrome Canary page. Several developers have reported installing the wrong version and wondering why the flag was missing.
Enable WebMCP Flag
Navigate to chrome://flags/#enable-webmcp-testing, set "WebMCP for testing" to Enabled, and click Relaunch at the bottom of the page.
Verify API Availability
Open DevTools (F12), go to Console tab, and run console.log(navigator.modelContext). An object (not undefined) confirms the API is available.
Install Model Context Tool Inspector
Install the Model Context Tool Inspector Extension from Chrome Web Store. It lists registered tools, lets you execute them manually, and has built-in Gemini API support for testing.
Enable File URL Access (for local testing)
Open the extension settings, go to Details, and enable access to file URLs so the extension can interact with your local HTML files during development.
Building Your First WebMCP Integration
There are two ways you can build your first WebMCP integration: the declarative approach using HTML annotations, and the imperative approach using JavaScript API.
The Declarative Approach (HTML)
The simplest way to register a WebMCP tool is to annotate a form that already exists on your page. Four attributes turn a standard form into an agent-callable tool: toolname, tooldescription on the form, and toolparamtitle and toolparamdescription on individual fields.
<form toolname="search_products"
tooldescription="Search the product catalog by keyword and optional category filter"
action="/search" method="GET">
<label for="query">Search term</label>
<input type="text" name="query" id="query" required
toolparamdescription="The keyword or phrase to search for">
<label for="category">Category</label>
<select name="category" id="category"
toolparamtitle="Product Category"
toolparamdescription="Filter results to a specific category">
<option value="all">All categories</option>
<option value="electronics">Electronics</option>
<option value="books">Books</option>
<option value="clothing">Clothing</option>
</select>
<button type="submit">Search</button>
</form>
What the browser does with those attributes is generate a JSON schema internally. The tool name, parameter types, enum values from select options, and required markers from HTML all carry over without additional configuration.
Agent Fills Form
Chrome focuses the form, populates fields with values the agent supplied, and stops there. The user still has to click Submit by default.
Auto-Submit (Optional)
Add toolautosubmit attribute to remove confirmation step. Use for read-only operations like search queries, not for data-modifying actions.
Intercept and Respond
Use respondWith() method on submit event to send structured results back to the agent instead of normal form submission.
Detect Agent vs Human
Use the agentInvoked boolean on submit event. True when agent triggered submission, false for human click. Branch your response formatting accordingly.
The Imperative Approach (JavaScript)
Forms cover a lot of ground, but some tools need to work with application state, make API calls, or return computed results that do not map to a traditional form submission. The imperative API gives you full programmatic control.
navigator.modelContext.registerTool({
name: "addTodo",
description: "Add a new item to the user's to-do list.",
inputSchema: {
type: "object",
properties: {
text: { type: "string", description: "The task description" },
priority: { type: "string", enum: ["low", "medium", "high"] }
},
required: ["text"]
},
execute: (params) => {
const { text, priority = "medium" } = params;
const newItem = { id: Date.now(), text, priority, done: false };
todoApp.addItem(newItem);
todoApp.renderList();
return {
content: [{ type: "text", text: "Added task: " + text }]
};
}
});
The execute callback receives the parameters the agent sent, runs your application logic, and returns a content array. Update the UI before returning, as agents sometimes check what the page looks like after a tool call to verify it worked.
You can register and unregister tools as the page state evolves. Register tools after user login, unregister them after logout. This dynamic registration is a key feature of WebMCP.
Handling Agent Invocation and Safety in WebMCP
The WebMCP specification assumes a human is watching. The authors at Google and Microsoft designed it around cooperative workflows, not autonomous operation.
Detecting AI vs Human Users
A new boolean property called agentInvoked appears on the SubmitEvent interface. When an agent triggers a form submission, the property is true. When a person clicks Submit normally, it is false.
toolactivated Event
Fires after an agent invokes a tool and Chrome pre-fills the associated form fields. Use toolName property to know which tool was involved.
toolcancel Event
Fires if the user cancels the operation or resets the form. Neither event is cancelable, but both carry a toolName property.
Rate Limiting
Check agentInvoked in submit handler and use respondWith() to return error messages when rate limits are exceeded.
Enforcing Human-in-the-Loop Permissions
With declarative tools, the default behavior is that the human has to click Submit after the agent fills in the fields. That default should stay in place for anything with real consequences.
| Tool Type | Auto-Submit | Use Case |
|---|---|---|
| Search Queries | Yes (toolautosubmit) | Read-only, low-risk operations |
| Availability Checks | Yes (toolautosubmit) | Status checks, lookups |
| Data Modification | No (default) | Creating, updating, or deleting data |
| Purchases | No (default) | Anything with payment or account changes |
For imperative tools with no form and no submit button, execution runs immediately when the agent calls the tool. Build confirmation into the tool itself for operations that should not happen without human approval, such as account deletion.
Testing Your WebMCP Implementation
Once you have your first WebMCP integration up and running, use the Model Context Tool Inspector Extension to test it thoroughly.
Verify Tool Registration
Check that tools show up in the extension panel after page load. If a tool does not appear, the registration did not work correctly.
Manual Execution
Select a tool from the dropdown, type a JSON object into Input Arguments field, and click Execute Tool. This removes non-deterministic elements from agent testing.
Test with Bad Parameters
Execute with invalid parameters. Check that your validation catches errors and that messages are clear enough for the agent to self-correct.
Natural Language Testing
Paste a Gemini API key into the extension settings, then type a natural language prompt. The extension sends it to Gemini 2.5 Flash alongside your tool definitions.
Test Edge Cases
Test unauthenticated users, disabled forms, API downtime, and rapid repeated calls to ensure strong behavior under all conditions.
Conclusion
WebMCP gives websites a direct communication channel with AI agents. Rather than agents guessing their way through a page, the site publishes structured tool definitions, and the agent calls them with typed parameters. The declarative API turns existing forms into agent-callable tools with a few HTML attributes. The imperative API covers everything more complex. The safety model keeps the human in control of actions that matter.
The spec is still early, available only in Chrome Canary behind a flag, and not suited for production use. But the fact that both Google and Microsoft are authoring it together, with W3C providing governance, suggests it has a real path to becoming a stable web standard. Spending time with the API now means you will already understand the tool design patterns and safety mechanisms when the stable release arrives.
If you want to start preparing now, audit the forms on your existing sites and identify which ones would benefit most from agent access. Search forms and availability checkers are low-risk starting points. Once you are comfortable with the declarative API, move to imperative tools for workflows that need custom logic.
Frequently Asked Questions
What are the two ways to implement WebMCP on a website?
WebMCP can be implemented in two ways: a declarative approach using HTML form annotations, and an imperative approach using JavaScript. The declarative approach is simpler and works well for existing forms, while the imperative approach offers more control for dynamic workflows, API calls, and custom validation.
Can I use WebMCP in production today?
Not yet. It sits behind a feature flag in Chrome Canary, and the W3C spec is still in draft. Use for prototyping and experimentation only.
Do other browsers support WebMCP?
Chrome has the only working implementation at the moment. Microsoft helped write the spec, which makes Edge support very likely down the road. Mozilla and Apple both have representatives in the W3C working group, but there are no published timelines from either.
Does WebMCP require a backend server?
No. With WebMCP, your existing frontend JavaScript becomes the agent interface. The tools run in the page context, use the same session the human user has, and need no additional infrastructure behind them.
What happens if I don't implement WebMCP on my site?
Nothing breaks. Agents continue to interact with your pages through screenshots and DOM scraping, the same way they do now. Those interactions will just be slower, more error-prone, and more computationally expensive for the agent.
Need Help with AI Implementation?
Our experts can help you implement WebMCP, agent-ready websites, and custom AI agent interfaces for your business applications.
WebMCP exposes tools from a web page; if you need your own back-office systems (ERP, CRM, inventory) reachable by an AI agent through a server-side Model Context Protocol endpoint, see our MCP server development services.
About the author
Founder & CEO, Braincuber Technologies
Founder and CEO of Braincuber. Scopes Odoo, AI, and cloud projects for growing brands in India and abroad. Takes every founder call personally — no SDR layer between buyers and the people building the system.
