Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

WebMCP Tools, Form Registration, Imperative API and Agent Security

How websites expose WebMCP tools via forms or JavaScript, annotate safety, debug in DevTools, and how that differs from MCP.

This page summarizes Chrome’s WebMCP documentation on exposing structured tools from a web page so browser-based agents can act on your site with explicit contracts instead of guessing the UI. WebMCP runs entirely in the browser tab, requires a secure context (HTTPS), and today supports tools only—not MCP-style resources or prompts.

WebMCP is a proposed web standard to help you build and expose structured tools for AI agents.

— Chrome, WebMCP

WebMCP: why expose tools instead of DOM actuation

Section titled “WebMCP: why expose tools instead of DOM actuation”

WebMCP gives agents a machine-readable list of capabilities, each with a JSON Schema for inputs, so they call defined functions instead of inferring buttons and fields from the DOM. Chrome describes this as more reliable than multi-step actuation (simulated clicks and typing).

WebMCP provides rules for interaction that bridge the gap between web applications and agents, improving efficiency, reliability, and task completion. Instead of an agent reviewing the element, such as a button or a field, to understand its purpose, the website declares the element’s purpose, so it’s used as intended.

— Chrome, WebMCP

In practice: your site registers tools, the browser presents them to a WebMCP-aware agent together with URL, title, and origin scope, and the agent supplies structured arguments while the user stays in the loop for permission and confirmation. See Reliable agent calls with WebMCP for the three-step flow.

WebMCP is not a replacement for the Model Context Protocol (MCP). They solve different layers:

MCP WebMCP
Where tools live Server Open web page
Availability While the server is up While the page/tab is open
Session Server credentials User’s current browser session
UI Often inside the agent app Your existing website

WebMCP is not an extension or a replacement of MCP.

— Chrome, When to use WebMCP and MCP

Many products use MCP for core business logic and WebMCP for in-tab, session-aware actions. WebMCP is described as MCP-inspired but browser-native—no HTTP/SSE transport from the page itself (WebMCP (Web Model Context Protocol)).

Declarative API: turn HTML forms into WebMCP tools

Section titled “Declarative API: turn HTML forms into WebMCP tools”

The Declarative API adds attributes to a standard <form>; the browser builds JSON Schema from controls. Unsupported browsers ignore the attributes and the form still works as HTML (Agentic Forms).

Form attributes agents and developers need

Section titled “Form attributes agents and developers need”
Attribute Role
toolname Unique tool name (required with tooldescription to register)
tooldescription What the tool does and when an agent should use it—not a repeat of field lists
toolautosubmit Optional; agent may submit without waiting for a manual click
toolparamdescription Optional per-control (or on <fieldset>) schema description; falls back to <label> or aria-description

Do not list the form’s fields, options, or limits: the browser already includes them in the schema it builds from the form controls.

— Chrome, Agentic Forms

Removing toolname or tooldescription unregisters the tool.

Agent-driven submit: SubmitEvent and lifecycle

Section titled “Agent-driven submit: SubmitEvent and lifecycle”

When an agent invokes a declarative tool, the form stays visible, fields are prefilled, and SubmitEvent.agentInvoked is true. Use preventDefault() and respondWith(promise) to return results to the agent without navigation (Declarative API).

toolactivated and toolcancel fire on document.modelContext (from Chrome 156; older builds used window—feature-detect as in Agentic Forms). CSS pseudo-classes :tool-form-active and :tool-submit-active highlight active agent interaction.

Skip the Declarative API for highly dependent fields, non-standard controls (canvas, rich text), or multi-step wizards—use the Imperative API or normal DOM interaction instead (Agentic Forms). Lighthouse warns when forms lack declarative WebMCP metadata because agents may still infer forms but less reliably.

Imperative API: document.modelContext.registerTool()

Section titled “Imperative API: document.modelContext.registerTool()”

The Imperative API registers JavaScript tools—ideal for SPAs where tools depend on route or state (Agentic JavaScript Tools).

Web pages are tool producers: You define and register tools using document.modelContext.registerTool(). That is all a web page needs to implement. You do not need to call getTools() or executeTool() on the page to expose tools to agents.

— Chrome, Agentic JavaScript Tools

Browser agents, extensions, and DevTools discover tools out-of-band. getTools() and executeTool() exist for in-page assistants and tests (Imperative API).

Registration, unregistering, and cross-origin exposure

Section titled “Registration, unregistering, and cross-origin exposure”

Pass an AbortSignal to unregister; there is no unregisterTool() (Agentic JavaScript Tools). Aborting registration does not cancel in-flight runs—long work must honor per-execution signal.

exposedTo lists secure origins allowed to discover tools across frames; consumers must pass getTools({ fromOrigins: [...] }). Cross-origin registration in iframes needs Permissions Policy allow="tools" on the iframe (WebMCP).

Descriptions, schemas, and execute behavior

Section titled “Descriptions, schemas, and execute behavior”
  • Put types, enums, defaults, and limits in inputSchema; tool description should state purpose and when to use the tool only (Agentic JavaScript Tools).
  • The browser does not validate arguments or apply schema defaults—do that in execute.
  • execute(input, { signal }): return JSON-serializable values; for recoverable errors return structured payloads like { error: "..." } because thrown errors surface to the agent as generic failures (Agentic JavaScript Tools).
  • Async tools that use fetch or other I/O must forward signal; only rethrow when signal.aborted indicates cancellation.
Annotation Meaning
readOnlyHint Tool only reads state
untrustedContentHint Output may include UGC or third-party data—agents should harden handling (Agent security considerations for WebMCP)
consequentialHint (Chrome 154+) High-stakes or irreversible action—signals confirmation; not enforcement by itself
debugging (Chrome 156+) Developer tooling, not end-user tasks

MANDATORY: Treat consequentialHint as a hint, not an enforcement mechanism.

— Chrome, Agentic JavaScript Tools

For React, Angular, or Vue, Chrome requires the official integrations (use-webmcp-tool, Angular experimental providers, @vueuse/core useWebMCP) instead of calling registerTool() directly from components (Agentic JavaScript Tools). TypeScript projects should use the webmcp-types package.

Use feature detection before calling the Imperative API in browsers without WebMCP:

if ('modelContext' in document) {
// Register tools
}

Build effective tools: strategy, errors, and limits

Section titled “Build effective tools: strategy, errors, and limits”

Build your user’s agentic workflows with WebMCP tools recommends defining the user goal, initial app state, and role-playing the conversation to decide which atomic tools you need—not one mega-tool per journey.

Enforcement stays in application code: authorization, sequence safety, and treating raw external text as non-authoritative (Build tools). On failure, return explicit guidance (wrong order, bad date format, business rule violations) so the agent can recover instead of a generic dead end.

WebMCP best practices add architectural rules: expose a coherent tool surface for the current page state, share one application service between UI and tools, resolve success only when UI/state matches, and register/unregister tools with page context. Prefer clear verb names (create-event vs start-event-creation-process), accept raw user strings (avoid making the model do math), and validate strictly in code.

Lighthouse agentic browsing lists registered tools via CDP; registering more than 40 tools triggers a warning about context cost and agent confusion. WebMCP tool security suggests character budgets: ~500 chars per tool description, ~150 per parameter description, ~30 per name, ~1.5K per tool output.

Security for tool authors and agent developers

Section titled “Security for tool authors and agent developers”

Protecting sites and users (tool builders)

Section titled “Protecting sites and users (tool builders)”

WebMCP tool security focuses on hints, minimal cross-origin exposure via exposedTo, and keeping secrets off client-side tool code. Only expose write-capable tools to origins you would trust to act for the user.

Protecting agents from malicious page content

Section titled “Protecting agents from malicious page content”

Agent security considerations for WebMCP targets agent implementers. Two attack vectors stand out:

  1. Malicious manifests—hidden instructions in tool names, parameters, or descriptions.
  2. Contaminated outputs—untrusted third-party data in tool responses (e.g. comments).

LLMs treat all text, instructions and user data, as a single sequence of tokens. This means that they’re susceptible to indirect prompt injection.

— Chrome, Agent security considerations for WebMCP

Deterministic guardrails include token limits on inbound tool payloads, restricting which origins the agent may call, user confirmation for mutating tools (assume mutation unless readOnlyHint says otherwise), and honoring untrustedContentHint with spotlighting (delimiting or Base64-wrapping untrusted text in system instructions).

Probabilistic guardrails include injection classifiers (e.g. scanning tool descriptions and outputs before the agent sees them) and critics that check planned tool calls against user intent without ingesting untrusted tool output. Red-team with tools such as Promptfoo; evaluate continuously as attacks evolve (Agent security considerations).

The WebMCP pane under Application shows Available Tools (live registry) and Invoked Tools (inputs, outputs, status). You can run tools manually without waiting for an agent—useful for schema and logic checks.

Debug WebMCP tools with AI agents describes using DevTools for agents so a coding agent can list tools, execute them, and review schemas when agents mispredict parameters.

Before production, Test WebMCP with Evals recommends combining classic JS tests for execute logic with probabilistic evals for tool choice and argument mapping. Test tools in isolation via document.modelContext.executeTool() when agent selection fails in complex journeys.

  1. Enable WebMCP locally per WebMCP (flag or origin trial) and load your page over HTTPS.
  2. Open Chrome DevTools → Application → WebMCP and confirm Available Tools lists expected declarative and imperative tools with sensible descriptions.
  3. Manually Run tool from the panel with valid and invalid inputs; confirm structured errors return to the agent instead of opaque failures (Agentic JavaScript Tools).
  4. Run Lighthouse Agentic Browsing (Chrome 150+) if enabled: check Registered WebMCP tools and schema validity audits.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about so it can be corrected.