Awesome Testing

Field note

Understanding WebMCP with Playwright and AI Agents

Oct 11, 202613 min read

TestingAI#WebMCP#Playwright#MCP#Agentic Testing

Last week, I wrote about e2e, a new framework for end-to-end test automation. The framework also has some interesting features for exploratory testing and visual testing that I want to try. I will return to those in another post.

There is quite a lot happening around AI agents at the moment. Alongside new models and testing frameworks, we are seeing standards and interfaces that define how agents work with other software. We already have MCP for connecting agents to external tools. WebMCP is another proposal in that direction, this time allowing websites to expose their own operations to agents through the browser.

Today, I want to focus on WebMCP. The timing is not accidental: Playwright 1.64 has just added support for it. I want to explain how it works, what website owners need to implement, and show a short practical demo, as usual, using my Awesome LocalStack.

What Is WebMCP

A browser agent can already read a page, fill in a form and click a button. To do that, it needs to understand the interface and work out which controls to use. WebMCP gives the website another way to make its functionality available: it can expose operations as tools that an agent can call.

For example, a website could offer a tool for searching its catalogue or checking an order. The agent receives a description of what that operation does and which arguments it accepts. It can then request the operation directly, without having to express every step as a sequence of clicks.

The website owner has to implement this support. WebMCP does not automatically turn every button into an agent tool. The development team decides which operations to expose. For each tool, it provides a name, a description, an input schema and a JavaScript function that performs the operation. The schema describes the expected arguments, such as a search phrase or an order number. The function contains the application code, or connects to code the website already uses. The page registers the tool with the browser's WebMCP API.

When a compatible agent visits the page, its browser integration can discover the available tools. The agent chooses a tool that fits the user's request and supplies its arguments. The browser passes the call to the function registered by the website. That function performs the operation and returns a result, which the agent can use to answer the user or decide what to do next.

Here is the same flow in a simplified diagram:

WebMCP flow: a website registers tools, an AI agent calls them through the browser, and the handler returns a result.

The website owner supplies the tool definition and handler. The browser mediates calls and returns results to the agent.

The operation runs in the context of the website. If it needs to call a backend, it can use the application's existing client and session. The application still needs to validate the input and check whether the user is allowed to perform the action. Describing an operation as a tool does not replace those checks.

The name is related to MCP, but the integration is different from running a separate MCP server on the backend. Here, the website exposes JavaScript operations through the browser. Both the browser and the agent's integration need to support that interface.

WebMCP is still experimental. The specification is currently a Community Group draft, rather than a W3C standard. Before trying it, we need to check all three participants: the website must expose WebMCP tools, the browser we use must implement the API with the feature enabled, and the agent's harness or browser integration must support discovering and calling those tools. Support in just one or two of them is not enough. The API and its browser and client support can still change.

Website Owners Need to Add Support

Website owners have to add WebMCP support before agents can use their page-defined tools. The development team chooses which operations to expose, supplies descriptions and argument schemas, and connects each operation to application code. In the JavaScript approach used by this demo, the page registers these definitions with the browser. This integration is part of the website itself. WebMCP specification.

There are three participants:

ParticipantResponsibility
Website owner and development teamImplement the tools, validate their inputs, enforce application permissions and keep visible state consistent
BrowserImplement the WebMCP API and make registered tools available to compatible callers
Agent harness or automation toolSupport WebMCP discovery and invocation, so the agent can choose a tool and provide its arguments

An agent can continue using ordinary browser interactions on a website that has not added WebMCP support. Page-defined tools become available when the site implements them and the browser and caller support the feature.

At the time of writing, we cannot assume that even a regular Chrome session has WebMCP available. For the Chromium browser used in this demo, we need to launch it with --enable-features=WebMCP. Without that flag, the shop shows “WebMCP unavailable in this browser” and cannot register its native tools. This is why we need to check all three participants, including the browser version and configuration, before trying the integration. See the Playwright browser requirements.

This distinction matters for the Playwright announcement. Playwright now supports discovering and calling the tools a page has registered. Website owners still need to implement those tools. The new automation API provides access to that interface. Playwright WebMCP API.

For my shop, I exposed three existing product and cart operations. You can see the implementation in the frontend commit that adds WebMCP support. They use the application's authenticated clients and backend rules. The tools also update the visible page, so a user can see the results of the agent's actions.

WebMCP in the Live Shop

The demo is already deployed. Open the products page with its inspector expanded after signing in with your training account.

The shop registers three tools with the browser: search_products, add_to_cart and get_cart. Playwright can then discover their names, descriptions and input schemas through page.webmcp.tools().

The shop registers search_products, add_to_cart and get_cart with WebMCP inside the browser. Playwright discovers the three tools through page.webmcp.tools().

The shop defines the tools, the browser exposes them, and Playwright retrieves their definitions. This is discovery; calling a tool is the next step.

A tool search changes the existing search field, selects ascending price order, applies the stock filter and clears the category selection. An addition updates the shared cart state, so the existing product card and navigation badge reflect the saved quantity.

The inspector shows the three schemas, recent tool arguments and results, and the path from the agent through the page tool and shop API to shared UI state. This makes it possible to observe what the website exposes and what the agent calls.

The fault lab adds explicit scenario controls for a broken button, a wrong product, a stale cart display and an incorrect displayed total. These controls affect the lab. The original products page uses the healthy implementation.

Both interfaces use the deployed training backend and save actual cart changes.

Registering the Page Tools

The demo exposes three operations:

ToolArgumentsBehavior
search_productsquery, optional inStockOnlyReturns matching products ordered by price and updates the visible filters
add_to_cartproductId, quantityAdds additional units to the signed-in user's saved cart
get_cartEmpty objectReads the saved cart and refreshes its visible state

As with MCP, the tool description is especially important because the agent uses it to decide which tool to call and how to use it. It should be precise and match what the operation actually does, including its side effects. In this shop, quantity means additional units. Calling add_to_cart with two, then calling it again with one, leaves three units in the cart. A successful add is not idempotent, so repeating it after an uncertain result can duplicate the addition.

We should also design these tools with agents in mind. Ideally, an error message explains what went wrong and gives the agent a useful next step. For example, if the requested quantity exceeds the available stock, the response could state how many units are available so the agent can adjust its request. If a product ID is unknown, it could suggest searching the catalogue again. Clear errors help the agent correct its mistakes instead of repeating the same failed call.

The schema describes the input, but the implementation also validates it. Quantities and product IDs must be positive safe integers. Unknown arguments are rejected. An application error returns isError: true; it must not look like a successful cart write to the caller.

A shortened registration example looks like this:

const lifetime = new AbortController();

await document.modelContext.registerTool({
  name: 'add_to_cart',
  description: 'Add additional units to the signed-in user\'s cart.',
  inputSchema: {
    type: 'object',
    additionalProperties: false,
    properties: {
      productId: { type: 'integer', minimum: 1 },
      quantity: { type: 'integer', minimum: 1 },
    },
    required: ['productId', 'quantity'],
  },
  execute: async ({ productId, quantity }) => {
    const response = await cart.addToCart({ productId, quantity });
    updateVisibleCart(response.data);
    return {
      content: [{ type: 'text', text: JSON.stringify(response.data) }],
    };
  },
}, { signal: lifetime.signal });

// React effect cleanup when leaving the route:
lifetime.abort();

This excerpt omits the runtime validation and error handling present in the source. It shows the relationship between the tool and the existing application client.

The demo was tested with Playwright 1.64.0 and bundled Chromium 156.0.8078.4, using the experimental WebMCP feature. That browser exposes document.modelContext; some documentation and older examples still refer to navigator.modelContext. The implementation ties registration to the page's lifetime with an AbortSignal, removing the tools when the user leaves the shop route.

Trying the Production Demo

Use the live products page to inspect the available operations. A compatible browser and agent with WebMCP support can discover the three tools and carry out a task such as:

Confirm my cart is empty. Find the cheapest available book, add two units, and report the total. Stop before checkout.

The agent should first read the cart, then search the catalogue, use an ID from the returned products and request the addition. Finally, it should read the saved cart and check the visible result. The inspector lets us follow the calls alongside the normal product interface.

WebMCP remains experimental, so browser compatibility matters. The ordinary shopping UI and inspector can be viewed without native WebMCP support; calling the native tools requires a compatible browser with the feature enabled. The Playwright documentation describes its current browser requirements.

These are real cart changes in the training application. Use your own training account and an empty cart for the experiment, then remove the items you added. Product IDs should come from the current catalogue.

In my CLI walkthrough, the catalogue returned Clean Code at $44.99. Adding two produced $89.98 in the saved cart. The UI baseline, with tools disabled, reached the same result. This is an example of the interfaces agreeing on a concrete shopping operation. It is not a controlled benchmark of an LLM's reasoning speed or success rate.

What Playwright Now Supports

Playwright 1.64 adds page.webmcp for the main page and frame.webmcp for individual frames. We can list the tools a page exposes and invoke a named tool with structured arguments:

const tools = await page.webmcp.tools();
const result = await page.webmcp.callTool('search_products', {
  query: 'Books',
  inStockOnly: true,
});

Playwright MCP also offers page-defined tools to agents using the webmcp_<tool> naming pattern. Playwright CLI exposes discovery and invocation through webmcp-list and webmcp-call. This gives us access from conventional tests as well as agent workflows.

The responsibilities stay distinct: the website defines the business operations, and Playwright supplies the automation interface for discovering and exercising them.

Testing WebMCP with Playwright

We can test the website's tool contracts with ordinary Playwright assertions. For example, a test can check discovery and then add two units of a product prepared by its fixture:

const tools = await page.webmcp.tools();

expect(tools.map(tool => tool.name).sort()).toEqual([
  'add_to_cart',
  'get_cart',
  'search_products',
]);

const result = await page.webmcp.callTool('add_to_cart', {
  productId: seededCable.id,
  quantity: 2,
});

expect(result.isError).not.toBe(true);
const reportedCart = JSON.parse(result.content[0].text);
expect(reportedCart).toMatchObject({ totalItems: 2, totalPrice: 25 });

No LLM is needed for this test. Playwright calls a named tool with deterministic arguments and checks a deterministic result. An agent choosing which tool to call is a separate behavior to evaluate.

Checking only the return value would be weak evidence. The demo therefore checks three observations: the tool result, the visible UI and a separate authenticated HTTP read from the backend. For the seeded cable, two units at $12.50 must produce $25.00 in all three places.

On the original products page, the test checks the product card's 2 in cart label and quantity. In the lab, it checks the cart total displayed beside the catalogue. The backend read confirms the saved product ID, quantity and total independently of the tool's report.

Each test creates a fresh client and three namespaced products: a $12.50 cable, a $25 charger and an unavailable $1 adapter. The client performs the cart operations. Admin access is used only for fixture setup and cleanup. The fixture clears its cart, removes its products and deletes its user afterward.

The browser suite also covers repeated additions, rejected stock writes, unknown products, authentication, fresh cart reads, route cleanup and mobile layouts. It runs against a local training backend, not the shared production dataset.

A Free WebMCP Testing Playground

I added the WebMCP shop lab as an extension of Awesome LocalStack, my environment for practising software testing. It is free to use, so you can try the integration yourself and experiment with your own tests or agent workflows.

After signing in with your training account, start with the healthy application and then select one of the four deliberately faulty scenarios. You can compare what happens when you use the normal interface with what happens when an agent calls a WebMCP tool. The inspector shows the calls and their results; checking the visible cart and saved data lets you see whether those results tell the whole story. Native tool calls require the browser and agent support described earlier.

The scenarios give you a known defect to investigate. Try writing a test that detects it, or give your agent a shopping task and see whether it notices the problem:

Deliberate faultTool resultSaved backend dataVisible UI
Broken Add to cart buttonTool addition succeedsCorrect product and quantityClicking the button does nothing
Tool adds another productReports the cart containing the wrong productWrong product is actually savedShows the wrong item
Tool leaves cart display staleCorrect saved cartCorrect product and quantityStill displays an empty cart
Displayed total is one cent too highCorrect $25.00 totalCorrect $25.00 totalDisplays $25.01

A Broken Button

I make the lab's Add to cart click do nothing. A normal UI test detects that the cart stays empty. Calling add_to_cart still succeeds because the callback uses the application client directly.

This is the clearest limitation of treating a tool test as an end-to-end test of the human interface. The business operation can work while the control a customer uses is broken. A passing WebMCP test does not exercise that button.

The Wrong Product

The requested cable costs $12.50. The faulty tool sends the charger's ID to the backend instead. Adding two saves the charger and produces $50.00.

A test that checks only for the existence of a successful response can pass. A test that checks the requested product ID and expected total fails. An independent backend read also shows that the error is in the actual saved cart, rather than just the tool's wording.

A Stale Cart Display

The tool adds the correct cable and returns $25.00, but I omit the UI update. The backend also contains $25.00. The lab still displays $0.00.

Both API observations agree, but the customer sees stale state. This is why I explicitly connect the original products page's tools to the shared query cache and test its visible product cards.

An Incorrect Displayed Total

Finally, the tool and backend report $25.00, while the lab renders $25.01. Again, checking only the tool response misses the defect. We need to assert what is rendered.

You can use these scenarios as small testing exercises: decide which observation should detect the defect, add an assertion, and compare the healthy and faulty behavior. The faults are deliberate and apply to the lab. Use your own training account and clear the items you add when you finish.

Summary

WebMCP looks like an interesting proposal for a standard. It gives website owners a way to expose useful operations to agents, with descriptions and structured inputs, while using the application's existing logic. Playwright's new support makes it easier to experiment with that interface and test the tools a website provides.

There is still a lot to settle. The specification is a Community Group draft, browser support is experimental, and the agent's harness needs a compatible integration. Until the specification is more stable and support becomes broader, I see WebMCP as something worth exploring rather than something I would build a production strategy around.

For now, it is an interesting experiment, not evidence that the internet or agent-based coding is about to change completely. The free shop lab is a place to try it and form your own opinion. And from a testing perspective, the lesson already applies: a tool returning success does not prove that the human interface works or that the right data was saved.

WebMCP in AI Wiki

I also added a WebMCP entry to my AI Wiki. It explains the protocol without focusing on a particular automation tool: what the website exposes, how the browser connects it to an agent, and where permissions and application logic fit into the flow. You can follow the links to related topics such as MCP and tool calling, as well as the original specification.