DEV Community

Cover image for WebMCP Testing: How to Test and Debug WebMCP Tools in Chrome
Hassann
Hassann

Posted on Originally published at apidog.com

WebMCP Testing: How to Test and Debug WebMCP Tools in Chrome

WebMCP testing in Chrome comes down to four checks. Turn on chrome://flags/#enable-webmcp-testing, open DevTools > Application > WebMCP and confirm the tool is listed with the schema you expect. Run it by hand with Run tool, then read the Input and Output of every call in the Invoked Tools log. If the tool calls a backend API, test that API's contract on its own as well. Most "registered but failing" bugs show up in one of those four places.

Try Apidog today

What is WebMCP testing?

WebMCP testing is the practice of checking that the tools a web page registers with document.modelContext are discoverable, accept the arguments their JSON Schema promises, run without throwing, and return output an agent can use. It covers four layers: registration, input validation, execution, and the backend API the tool calls.

WebMCP is a proposed web standard, published as a W3C Community Group draft. A page registers tools in JavaScript (the Imperative API) or by annotating an HTML form (the Declarative API). An agent in the browser then calls those tools directly instead of clicking through the DOM.

Why a registered WebMCP tool still fails

A tool in the registry proves only that registration ran. A recent debugging walkthrough on dev.to describes the classic case: the agent finds the right tool, Chrome shows the registration, and the app still answers INVALID_ARGUMENTS. The cause was a contract mismatch. The schema advertised id, the callback expected eventId.

Here are the failure layers and where each one shows up:

Layer What goes wrong Where you see it
Registration Tool never registers, or registers after the agent reads the list Missing from Available Tools
Selection Agent picks another tool or none Invocation counter stays at 0
Input Schema field names or enums differ from what execute() reads Input pane, error in Output
Execution execute() throws or returns something that can't be serialized Status: Error
Backend The API behind the tool returns a different shape or status Wrong data in Output, wrong UI state

Schema diagram of the WebMCP call path: an agent calls Chrome, which reads document.modelContext, runs the tool's execute function and calls the backend API, with DevTools, chrome-devtools-mcp and Apidog CLI each checking a different layer

The Chrome evals guide splits the same problem in two. The tool can fail, and the agent can fail to use it. Deterministic tests catch the first; evals against a real model catch the second.

Set up Chrome for WebMCP testing

You need a Chrome build with WebMCP turned on. For local work:

  1. Open chrome://flags/#enable-webmcp-testing.
  2. Set the flag to Enabled.
  3. Relaunch Chrome.
  4. Load your page and open DevTools.

To ship WebMCP tools to real users, Chrome runs an origin trial starting in Chrome 149. The WebMCP repo's implementation status page lists a @w3c/webmcp-polyfill package for browsers without native support; it lets you register and test tools, but a browser agent still needs native support to connect.

One gotcha: the tools Permissions Policy defaults to self, so a tool in a cross-origin iframe won't register unless the iframe has allow="tools".

Debug WebMCP tools with the DevTools WebMCP panel

Chrome DevTools has a WebMCP pane: open DevTools, click Application, and select WebMCP in the sidebar.

Available Tools lists every tool on the tab with its name and description as the agent sees them, plus an invocation counter. Check this first. If your tool is missing, the bug is in registration, not in the agent. If it's listed but the counter stays at zero after a prompt that should have used it, look at the name and description, not the code.

Invoked Tools is a log of every call. Select an entry to see:

  • Status: Completed, Canceled, In Progress or Error.
  • Input: the exact parameters the agent predicted and sent.
  • Output: the return value, or the error message.

The Input pane solves most contract bugs. Put it next to the code that destructures the arguments in execute() and compare field names. You can filter the log by name, status, and tool type (declarative or imperative).

Run a tool by hand

You don't need an agent to test a tool. Click it in Available Tools, fill in the parameters in the manual test area, and click Run tool. To replay a failed call, hover over it in Invoked Tools and click the Play icon: the test area opens with that call's parameters filled in.

When parameters or return values don't match the schema, DevTools shows the schema violation in the output pane. That catches an outputSchema (Chrome 159 and later) your execute() no longer honours.

Test WebMCP tools from the console

The same checks work from the console. The Imperative API docs define getTools() and executeTool():

const tools = await document.modelContext.getTools();
console.table(tools.map(t => ({ name: t.name, origin: t.origin })));

const addTodo = tools.find(t => t.name === 'addTodo');
const result = await document.modelContext.executeTool(addTodo, { text: 'Buy milk' });
console.log(result); // 'Added to-do: Buy milk'
Enter fullscreen mode Exit fullscreen mode

getTools() returns tools sorted by name, same-origin only by default. Pass { fromOrigins: ['https://partner.org'] } to include a cross-origin iframe's tools, which also have to list your origin in exposedTo. executeTool() resolves to the tool's result, or null when the tool triggers a navigation. Pass the input as an object: Chrome deprecated JSON-stringified input from Chrome 155.

Also check:

  • Late registration. If tools register after an async fetch, call document.modelContext.waitForToolsUntil(promise) (Chrome 160).
  • List changes. Listen for toolchange on document.modelContext to confirm a tool actually unregisters when you abort its AbortSignal.
  • Declarative forms. A form with toolname and tooldescription becomes a tool. In its submit handler, e.agentInvoked is true for agent calls, and e.respondWith(promise) returns the result after preventDefault().

Let your coding agent test WebMCP tools

A coding agent can do the clicking. Chrome's DevTools MCP server ships two WebMCP tools, list_webmcp_tools and execute_webmcp_tool. They're off by default; add the flag:

"args": ["chrome-devtools-mcp@latest", "--categoryExperimentalWebmcp"]
Enter fullscreen mode Exit fullscreen mode

Now Claude Code or Codex can open your page, list its tools, and call each one with valid and invalid input: a missing required field, a value outside the enum, an empty string. For an MCP server rather than in-page tools, use MCP Inspector instead.

WebMCP inside MCP Apps: what the 2.1 bridge changes

If your page also runs as an MCP App, there's one more layer. The ext-apps v2.1.0 release added WebMCP interoperability. Tools registered with App.registerTool() are mirrored into document.modelContext when the document provides it. Tools on document.modelContext are served over the Apps tools/list and tools/call channel, and toolchange is relayed as notifications/tools/list_changed. You can switch the bridge off per app with webMcpBridge: false.

So one tool can be called from two directions; test both. A second dev.to post reports that app-registered tools win name collisions and that not every WebMCP annotation has an MCP Apps counterpart. That's the author's testing, not the release notes, so check the WebMCP panel for duplicate names on your own build.

Test the API behind your WebMCP tool with Apidog CLI

Most real tools are thin wrappers. execute() reads the arguments, calls your REST API, and returns a summary. When the output is wrong, you need to know whether the tool or the API changed. A separate API contract test answers that in seconds.

Let your coding agent write and run those checks with Apidog CLI. Set it up once:

npm install -g apidog-cli@latest
apidog login --with-token <YOUR_TOKEN>
npx -y skills add https://apidog.com   # pick your agent when prompted
Enter fullscreen mode Exit fullscreen mode

Then give your agent one prompt:

In Apidog project <projectId>, create a test scenario called "WebMCP tool backend contract"
with three custom HTTP steps for the API my addTodo and getTodo WebMCP tools call:
POST /todos with the tool's input (expect 201, the title echoed back and an id),
GET /todos/1 (expect 200 with title and completed fields), and GET /todos/999999
(expect 404, the error path the tool must handle). Read the CLI schema and validate
the payload before writing, then run it and summarize any failures.
Enter fullscreen mode Exit fullscreen mode

The agent reads the schema, validates its payload, creates the scenario and runs it:

apidog cli-schema get test-scenario-update
apidog cli-schema validate test-scenario-update --file steps.json
apidog test-scenario create --project <projectId> --name "WebMCP tool backend contract" --folder-id 0
apidog test-scenario update <scenarioId> --project <projectId> --file steps.json
apidog run -t <scenarioId> --project <projectId> -e <envId> -r cli
Enter fullscreen mode Exit fullscreen mode

Here's that run against a public demo API standing in for the tool's backend. All 7 assertions pass:

Apidog CLI running a sandbox scenario that tests the API behind a WebMCP addTodo tool: POST returns 201, GET returns 200, an unknown id returns 404, 7 of 7 assertions pass

The third step matters most for WebMCP. When the agent sends an ID that doesn't exist, your execute() has to turn a 404 into a message the model can act on, not a thrown error. If the API ever returns 200 with an empty body instead, the test fails before your tool misleads the agent.

Add -r junit and the same apidog run goes into CI. The CI/CD pipeline guide shows the setup, and the apidog run reference lists every flag.

Once a team has several of these agent-driven checks, Sharkly turns them into board tasks: each one goes to a coding agent running on a teammate's own computer with their own Claude Code or Codex plan, and you review what the agent ran before it merges. It's free to start.

WebMCP testing checklist

  1. The tool appears in Available Tools with the name and description you wrote.
  2. Every field execute() reads is in inputSchema, with the same name and type.
  3. Enums and required match what the code validates. Keep runtime validation even when the schema is right.
  4. Run tool with valid input completes. With invalid input it returns a readable error, not a stack trace.
  5. The return value is JSON-serializable and matches outputSchema if you set one.
  6. readOnlyHint only on tools that change nothing; consequentialHint on anything that books, pays or deletes.
  7. The backend API has its own passing contract test.

Sequence diagram of a manual WebMCP test: the developer runs a tool from the DevTools WebMCP panel, Chrome calls execute, execute calls the backend API, a 404 comes back and the tool returns a readable error that shows in the Invoked Tools log

FAQ

How do I enable WebMCP in Chrome? For local development, open chrome://flags/#enable-webmcp-testing, set it to Enabled, and relaunch. For production users, join the WebMCP origin trial, which starts in Chrome 149.

Where is the WebMCP panel in Chrome DevTools? Open DevTools, click the Application tab, and select WebMCP in the sidebar. It shows Available Tools with an invocation counter and an Invoked Tools log with the status, input and output of each call.

How is WebMCP testing different from testing an MCP server? An MCP server exposes tools over a protocol endpoint, so tools like MCP Inspector can connect to it. WebMCP tools live in a page's JavaScript and need a browser tab, so you test them with DevTools, the console or chrome-devtools-mcp.

Why does my tool register but never get called? Check the invocation counter. If it stays at zero, the agent didn't pick the tool, so rewrite the name and description to state what it does and when to use it. If the counter climbs but calls fail, compare the Input pane with your execute() arguments.

Top comments (0)