Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 12 min read

A Minimal WebMCP Demo in Chrome: Typed, Tested Headless, and Driven by an Agent

WebMCP lets a web page hand an AI agent a set of tools: named functions with a description and a JSON Schema for their input, registered on document.modelContext. A to-do page with four of them, about 95 lines of plain J

WebMCP lets a web page hand an AI agent a set of tools: named functions with a description and a JSON Schema for their input, registered on document.modelContext. A to-do page with four of them, about 95 lines of plain JavaScript, is enough to exercise the whole API: imperative tools, a read-only annotation, an error path and a declarative form tool.

Every check here runs without a model or an API key. tsc checks each tool's handler against its own schema through webmcp-types. A headless Chrome test calls all four tools through puppeteer and passes all 4 tests. Google's webmcp-evals smoke runner passes 5/5 scripted tool calls. make demo opens a Chrome window with WebMCP and on-device tool calling switched on and the agent extension loaded.

Then a model drives the page. Through Google's webmcp-extension agent and gemini-3.6-flash, 4 plain-English requests run 5 times each made every expected tool call in 20 of 20 conversations, and all 5 answers to "how many items are still open?" quoted the count the page computed. With every permission prompt denied, no write reached the page and the read-only tool still ran.

This article provides a step by step guide to setting up, validating and testing a minimal WebMCP page in Chrome 158 with the three tools the Chrome WebMCP team released: webmcp-types, webmcp-extension and the evals in webmcp-tools.

https://github.com/xbill9/webmcp-mvp

The Findings

Read through puppeteer, Chrome reports a tool differently from how the page wrote it. The page sets readOnlyHint: true; the tool comes back with readOnly: true. A handler that returns JSON text comes back with output already parsed into an object. A handler that throws comes back with status: "Error", an empty errorText and the message in exception.description.

Branded Chrome 158 ignores --load-extension. Launched with it, Chrome started no extension. Loaded through puppeteer's enableExtensions, the agent extension's service worker started.

Chrome flags can ship with a profile. Writing enable-webmcp-testing and prompt-api-tool-use into a fresh profile's Local State file switched on WebMCP and AIPromptAPIToolUse, the same as clicking them in chrome://flags.

The agent used the tools the way their descriptions asked. It added items with add_todo, read each new id from the result, completed the right one and answered the counting request with list_todos and status: "open".

readOnlyHint decides what an agent may run unasked. With every permission prompt answered "deny", add_todo and complete_todo never reached the page in 3 runs, while list_todos ran 4 times.

webmcp-types 0.2.1 types the imperative API only. Schema inference works: a handler that reads idx from a schema that declares id fails the type check. The declarative form API's SubmitEvent.agentInvoked and respondWith need a three-line declaration file.

  • 🟒 Type check, headless test and smoke test all pass with no model and no key.
  • 🟒 One command opens a ready-to-use Chrome window.
  • ⚠️ Tests that read tool results through puppeteer need the field names Chrome uses.
  • 🟒 The agent made every expected tool call in 20 of 20 conversations.
  • 🟒 Denied writes never reached the page; the read-only tool ran without a prompt.
  • ⚠️ In 1 of 3 denied runs the agent counted with status: "all" and called the result "open".
  • ❌ Chrome's on-device model reported unavailable on this machine, so the agent used Gemini through the extension's server.

At This Point You Should Have…

  • Google Chrome 155 or newer; this article used 158.0.8127.88 on Linux
  • Node.js 22.18 or newer; this article used 26.9.0
  • The GitHub CLI, gh, for fetching the agent extension
  • A desktop session for the demo window; the checks run headless
  • For Step 8, a Gemini API key, or a machine where Chrome's on-device model is available

Step 1 β€” Clone and Install

gh repo clone xbill9/webmcp-mvp ~/webmcp
cd ~/webmcp
make install     # puppeteer-core, typescript, webmcp-types, webmcp-evals, oxlint
make extension   # once: clones GoogleChromeLabs/webmcp-extension at f5681de and builds it

The versions this article ran:

Google Chrome 158.0.8127.88
node v26.9.0
puppeteer-core 25.19.0
typescript 5.9.3
webmcp-types 0.2.1
webmcp-evals 0.1.1
oxlint 1.95.0
webmcp-extension commit f5681debc5203dc50872f6364f77ca3ad8718e24

Step 2 β€” Register the Tools

The page registers three tools in JavaScript and declares a fourth in HTML. list_todos filters in the page and returns the exact count with the items, and its description tells the agent to quote that count:

document.modelContext.registerTool({
  name: "list_todos",
  description:
    "Lists to-do items. Filter with status; the response includes the exact count, so never count items yourself.",
  inputSchema: {
    type: "object",
    properties: {
      status: { type: "string", enum: ["all", "open", "done"], description: "Which items to return. Default all." },
    },
  },
  annotations: { readOnlyHint: true },
  execute: async ({ status = "all" }) => {
    const items = todos.filter((t) => status === "all" || (status === "done") === t.done);
    return JSON.stringify({ status, count: items.length, items });
  },
});

add_todo and complete_todo follow the same pattern; complete_todo throws for an id it cannot find. The form tool is the page's own form with three attributes:

<form id="add-form" toolname="add_todo_form"
      tooldescription="Adds a to-do item through the page's form.">
  <label for="title">Title</label>
  <input id="title" name="title" required
         toolparamdescription="Text of the to-do item.">
  <button>Add</button>
</form>

A person and an agent submit it through the same handler. When e.agentInvoked is true, the handler answers the agent with e.respondWith(...).

Step 3 β€” Open the Demo Window

make demo
node test/demo.mjs
Page:      http://localhost:8137/  (4 WebMCP tools)
Extension: loaded from /home/xbill/webmcp-extension/dist
Close the Chrome window to stop.

The window runs on its own profile in ~/.cache/webmcp-demo, so the everyday Chrome profile keeps its settings. The page's banner turns green when document.modelContext exists.

Step 4 β€” Run a Tool by Hand

In the demo window, press F12 and open Application β†’ WebMCP. Available tools lists the four tools. Select add_todo, enter {"title": "milk"} and click Run tool: "#1 milk" appears on the page, and Invoked tools records the input, the output and the status.

Tool Input Result on the page
add_todo {"title": "milk"} "#1 milk" appears
complete_todo {"id": 1} milk is crossed out
list_todos {"status": "done"} returns "count":1
complete_todo {"id": 99} error: "No to-do with id 99"
add_todo_form {"title": "bread"} the form fills in and waits for Add

Step 5 β€” Check Each Handler Against Its Schema

public/app.js starts with // @ts-check and a reference to webmcp-types, so tsc checks it with no build step:

{
  "compilerOptions": {
    "lib": ["ES2022", "DOM"],
    "types": ["webmcp-types"],
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "strict": true
  },
  "include": ["public/**/*.js", "public/**/*.d.ts"]
}

webmcp-types infers each handler's argument from its inline inputSchema. A copy of the page whose complete_todo handler reads idx fails:

public/app.js(87,23): error TS2339: Property 'idx' does not exist on type '{ id: number; }'.
public/app.js(88,47): error TS2304: Cannot find name 'id'.
public/app.js(89,54): error TS2304: Cannot find name 'id'.
tsc exit 2

The form tool's two SubmitEvent members come from public/declarative.d.ts:

interface SubmitEvent {
  readonly agentInvoked?: boolean;
  respondWith?(result: Promise<unknown>): void;
}

Step 6 β€” Test the Tools Headless

puppeteer-core 25 exposes the page's tools as page.webmcp.tools(), each with an execute() method. Chrome needs --enable-features=WebMCP:

browser = await puppeteer.launch({
  executablePath: CHROME,
  headless: true,
  args: ["--enable-features=WebMCP"],
});

The test checks the tool list, the read-only annotation, an add-complete-filter round trip with exact counts and the struck-through item in the page, and the error for an unknown id:

make test
βœ” page registers the three imperative tools and the form tool (301.283997ms)
βœ” list_todos is annotated read-only (0.381584ms)
βœ” add, complete and filter round-trip with exact counts (22.129657ms)
βœ” complete_todo reports an error for an unknown id (1.261671ms)
β„Ή tests 4
β„Ή suites 0
β„Ή pass 4
β„Ή fail 0
β„Ή cancelled 0
β„Ή skipped 0
β„Ή todo 0
β„Ή duration_ms 618.089012

Step 7 β€” Smoke Test With webmcp-evals

webmcp-evals reads test cases as a user message plus the tool calls it should produce. Its smoke command skips the model and runs those calls in order against the live page, so the same file later drives a model run:

{
  "name": "Add then complete",
  "messages": [{ "role": "user", "type": "message", "content": "Add eggs and tick it off." }],
  "expectedCall": [
    { "functionName": "add_todo", "arguments": { "title": "eggs" } },
    { "functionName": "complete_todo", "arguments": { "id": 1 } }
  ]
}

make smoke serves the page on a free port of its own and runs the three cases:

Smoke Test Summary for http://localhost:40061/

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Case              β”‚ Step β”‚ Status β”‚ Tool          β”‚ Error β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Add then list     β”‚ 1    β”‚ PASS   β”‚ add_todo      β”‚ -     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Add then list     β”‚ 2    β”‚ PASS   β”‚ list_todos    β”‚ -     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Add then complete β”‚ 1    β”‚ PASS   β”‚ add_todo      β”‚ -     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Add then complete β”‚ 2    β”‚ PASS   β”‚ complete_todo β”‚ -     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Use the form      β”‚ 1    β”‚ PASS   β”‚ add_todo_form β”‚ -     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

Passed steps: 5/5 across 3 case(s).

make check runs lint, the type check, the test and the smoke test together.

Step 8 β€” Hand the Page to an Agent

webmcp-extension puts an agent in Chrome's side panel. It reads the page's tools, sends the conversation to a model and runs the tools the model calls. It can use Chrome's on-device model through the Prompt API, or a cloud model through a small local server. On this machine the on-device model is unavailable:

node docs/webmcp-mvp/evidence/check-ondevice.mjs
headless=true LanguageModel.availability(): unavailable
headless=false LanguageModel.availability(): unavailable

So the extension's server answers with Gemini. Put the key in ~/webmcp-extension/.env as GEMINI_API_KEY=, then start it:

cd ~/webmcp-extension && npm run server
πŸ€– Answering with google:gemini-3.6-flash
πŸš€ Backend model server listening on http://127.0.0.1:3100

PORT=3100 in the same .env moves the server off port 3000; npm run build then points the extension at it.

webmcp-evals browser --extension drives the extension's side panel in headless Chrome: it sends each request in evals/agent.json, answers the permission prompts and records every tool call the agent makes on the page. make agent serves the page and runs it:

RUNS=5 make agent

The four requests and what the agent did, from agent-summary.py over the saved report:

Request Runs with every expected call Calls the agent made in each run
Add milk to my list. 5 of 5 add_todo milk
Add milk, eggs and bread to my list. 5 of 5 add_todo Γ—3
Add milk and eggs, then mark eggs done. 5 of 5 add_todo Γ—2, complete_todo id 2
Add milk, eggs and bread, mark eggs as done, then tell me how many items are still open. 5 of 5 add_todo Γ—3, complete_todo id 2, list_todos open
calls by tool, all runs: {'add_todo': 45, 'complete_todo': 10, 'list_todos': 5}
list_todos status sent: {'open': 5}

Every counting answer quoted the tool's number:

    answer: 'I have added milk, eggs, and bread to your to-do list, and marked eggs as done.\n\nThere are currently 2 items still open (milk and bread).'
    count in answer: [2] | count list_todos returned: 2 | match: True

The agent never chose add_todo_form: the imperative tool returns the new id, which complete_todo needs.

The same counting request, run 3 times with CONFIRM=deny, shows what readOnlyHint controls. The extension asks before every tool without it, so all the writes were refused, and list_todos ran without asking:

== Count what is open: 0 of 3 runs passed every required call
  run 1: 2 calls, 3 turns: list_todos({"status":"open"}) -> list_todos({"status":"all"})
  run 2: 1 calls, 2 turns: list_todos({"status":"all"})
    answer: 'I tried to add "milk", "eggs", and "bread" to your to-do list, but the action was denied.\n\nAs a result, no items were added, and there are currently 0 open items in the list.'
  run 3: 1 calls, 2 turns: list_todos({"status":"open"})

In run 2 the agent asked for every item and reported the result as the open count. The list was empty, so the number was right by coincidence.

To try it by hand instead, open the demo window from Step 3, click the puzzle-piece icon, then WebMCP Extension, then Got it, and type a request into the side panel.

πŸ”Ž Tip: Read Results the Way Chrome Returns Them

node docs/webmcp-mvp/evidence/check-results.mjs
tools: add_todo, add_todo_form, complete_todo, list_todos
list_todos annotations: {"readOnly":true,"untrustedContent":false,"consequential":false,"debugging":false}
add_todo status: Completed | typeof output: object | output: {"id":1,"title":"milk","done":false}
complete_todo(999) status: Error | errorText: "" | exception.description: "Error: No to-do with id 999"

A test that checks annotations.readOnlyHint, calls JSON.parse(output) or matches errorText fails on Chrome 158. Check readOnly, accept an object, and read exception.description.

πŸ”Ž Tip: Ship the Flags With the Profile

chrome://flags stores its choices in the profile's Local State file. Writing it before Chrome first starts gives a window with the flags already on:

writeFileSync(join(PROFILE, "Local State"), JSON.stringify({
  browser: { enabled_labs_experiments: ["enable-webmcp-testing@1", "prompt-api-tool-use@1"] },
}));
flag switches: --flag-switches-begin --enable-features=PdfOopif,AIApiFoundationalModel:model_version/v4,AIPromptAPIToolUse,OnDeviceModelConversationBackend --enable-features=PdfOopif,AIApiFoundationalModel:model_version/v4,AIPromptAPIToolUse,OnDeviceModelConversationBackend,WebMCP --flag-switches-end
typeof document.modelContext: object

The extension loads through puppeteer, which needs pipe: true:

--load-extension: extension targets = []
enableExtensions: extension targets = ["service_worker"]

πŸ”Ž Tip: Let the Tool Count

list_todos returns count computed in the page, and its description tells the agent to quote it. A filter and a count done in code give the agent an exact number to repeat. In 5 of 5 allowed runs the agent sent status: "open" and quoted the 2 that came back. When checking an agent's answer, read the filter it sent as well as the number it quoted: in one denied run it sent status: "all" and called the result the open count, an exact number for the wrong set.

Compare and Contrast

Check Needs a model or key Needs a window What it covers
make typecheck no πŸ₯‡ no each handler against its schema
make test no πŸ₯‡ no discovery, results, counts, errors, page state
make smoke no πŸ₯‡ no scripted calls from an eval file, in order
DevTools WebMCP pane no yes one call at a time, by hand
make agent key or on-device model no whether a model picks the right tool and arguments
webmcp-extension side panel key or on-device model yes the same, typed by hand

So, Which One?

Run make check on every change: it needs nothing beyond Chrome and Node and covers the tools' contract. Use the DevTools pane while writing a tool. Run make agent when the question is whether a model reads your descriptions the way you meant them: the same eval format drives it, and the report shows the arguments the model sent. Deny the prompts once to confirm which tools an agent can run without asking.

Summary

The goal of this article was a minimal WebMCP page that can be set up, validated and tested without a model, then handed to an agent. The key to the solution was testing the tools through Chrome itself: webmcp-types for the schemas, puppeteer's page.webmcp for the calls, webmcp-evals smoke for scripted cases and webmcp-evals browser --extension for the agent. The results were:

  • 🟒 tsc with webmcp-types caught a handler reading a field its schema does not declare.
  • 🟒 The headless test passed all 4 tests and the smoke run passed 5/5 steps across 3 cases.
  • 🟒 make demo opened Chrome with WebMCP, on-device tool calling and the agent extension ready.
  • ⚠️ Through puppeteer, annotations, outputs and errors come back in Chrome's own shapes.
  • ⚠️ webmcp-types 0.2.1 needs a declaration file for the form API.
  • 🟒 Through webmcp-extension and gemini-3.6-flash, every expected tool call in 20 of 20 conversations.
  • 🟒 All 5 counting answers quoted the count list_todos returned.
  • 🟒 With prompts denied, no write reached the page and list_todos still ran.
  • ⚠️ In 1 of 3 denied runs the agent counted with status: "all" and called it the open count.
  • ❌ Chrome's on-device model reported unavailable on this machine.

Scope: one Linux machine on 2026-11-29, Chrome 158.0.8127.88 stable, Node 26.9.0, puppeteer-core 25.19.0, webmcp-types 0.2.1, webmcp-evals 0.1.1 and webmcp-extension at commit f5681de, with the checks in Steps 5 to 7 run once. The agent ran headless through webmcp-evals browser --extension with google:gemini-3.6-flash from the extension's server: 4 requests 5 times each with prompts allowed, and the counting request 3 times with prompts denied, each conversation on a fresh page. One model on one machine, 20 conversations with prompts allowed and 3 with prompts denied, shows how that model uses these tools; other models may choose differently. WebMCP is behind a flag and an origin trial from Chrome 149 and is still a proposed web standard, so the result shapes above may change between Chrome versions.

The strategy for building and testing WebMCP tools without a model was validated with an incremental step by step approach.

References

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.