WebMCP in React with human approval
Register a WebMCP tool in React and use Agent Pointer to show what it will do. Follow a Chrome-tested example that waits for approval before archiving a draft.
Register a WebMCP tool in a React effect with document.modelContext.registerTool(). WebMCP lets a page expose JavaScript functions for an agent to call. Here the tool requests a press of Archive draft, the same button a person would use. Agent Pointer moves to the button and shows an Approval card while the draft is still unsent. WebMCP draft, 29 Nov 2026
TL;DR
- Register
archive_draftand usepointer.run()to request a press of a UI SDK button withdata-agent-confirm. The button runs its archive handler after approval.- Turn on Chrome's WebMCP testing flag and call the tool from DevTools. Choose Deny to keep the draft, then call it again and choose Approve to archive it.
1. Set up React and install the components
Start with a React and TypeScript app. The first two lines set up a fresh Vite project. In a shadcn Vite project you already have, start with the add command. Keyframery setup for Vite
npx shadcn@latest init -t vite -b base --preset nova --no-monorepo --name webmcp-demo --yes
cd webmcp-demo
npx shadcn@latest add https://keyframery.com/r/agent-pointer.json https://keyframery.com/r/approval.json https://keyframery.com/r/button.json
npm install -D webmcp-types@0.2.1Keyframery is the animated component library for Vercel's UI SDK. The CLI installs the matching UI SDK packages and puts the components in src/components/keyframery. If you already use shadcn/ui, see the notes on shared CSS tokens. Using UI SDK with shadcn/ui
2. Register a WebMCP tool that asks for approval
Replace src/App.tsx with this example. The tool takes an empty object because it targets the one draft on the page. Archiving updates local React state.
import type {} from "webmcp-types"
import { useEffect, useState } from "react"
import { createAgent } from "@ui-sdk/react/agent"
import { AgentPointer, createAgentPointer } from "@/components/keyframery/agent-pointer"
import { createApprovals } from "@/components/keyframery/approval"
import { Button } from "@/components/keyframery/button"
const archiveLabel = "Archive draft"
export default function App() {
const [archived, setArchived] = useState(false)
const [pointer] = useState(createAgentPointer)
useEffect(() => {
const context = document.modelContext
if (typeof context?.registerTool !== "function") return
const lifetime = new AbortController()
const agent = createAgent({
allow: pointer.wrapAllow({
authorize: (step) => step.label === archiveLabel && step.action === "press",
approvals: createApprovals({ keep: 0 }),
}),
})
void context.registerTool({
name: "archive_draft",
description: "Archive the release notes draft after the person approves.",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
async execute(_input, { signal }) {
const result = await pointer.run({
...agent,
act(input, options) {
const signals = [signal, lifetime.signal]
if (options?.signal) signals.push(options.signal)
return agent.act(input, { signal: AbortSignal.any(signals) })
},
}, { steps: [{ ref: archiveLabel, action: "press" }] })
return result.ok
? { archived: true }
: { archived: false, reason: result.error?.message ?? "The draft was not archived." }
},
}, { signal: lifetime.signal }).catch((error: unknown) => {
if (!lifetime.signal.aborted) console.error("WebMCP registration failed", error)
})
return () => lifetime.abort()
}, [pointer])
return (
<main className="mx-auto grid max-w-2xl gap-4 px-6 pt-16">
<h1 className="text-xl font-semibold">Drafts</h1>
<div data-agent-pointer-scope className="grid justify-items-start gap-3 rounded-xl border p-4">
<p className="font-medium">Release notes</p>
<p role="status" className="text-sm text-muted-foreground">
{archived ? "Draft archived" : "Unsent draft"}
</p>
<Button
data-agent-confirm="Archive the unsent release notes draft"
disabled={archived}
onClick={() => setArchived(true)}
>
{archiveLabel}
</Button>
<AgentPointer controller={pointer} label="Agent" />
</div>
</main>
)
}authorize allows only a press of Archive draft. The button's data-agent-confirm value describes what the person is approving. Agent Pointer shows the card, and createApprovals() waits for the person's choice. The decision buttons are outside the set of controls the UI SDK agent can use. The Approval docs show how to apply a separate WebMCP caller policy when exposing tools through registerTools(). Approval component and WebMCP example
pointer.run() moves the pointer to the target and makes Take over available. Agent Pointer controller
The plan finds the button by its label. When a label changes, inspect the UI SDK snapshot to see what the bridge can find. Inspecting a control in Agent view
The effect aborts its registration signal on cleanup, which removes the tool. It also combines that signal with the tool caller's signal so a pending approval can close when the view unmounts or the caller cancels. React effect cleanup
3. Call the tool and check both answers
Use Chrome 155 or newer for the console call's object argument. Enable chrome://flags/#enable-webmcp-testing and relaunch. Run npm run dev, open the localhost URL Vite prints and paste this into DevTools Console. Chrome WebMCP setup, updated 7 Oct 2026
const context = document.modelContext
const tool = (await context.getTools()).find(({ name }) => name === "archive_draft")
if (!tool) throw new Error("The archive tool is unavailable")
JSON.parse(await context.executeTool(tool, {}))- Choose Deny on the page. The status stays Unsent draft and the console result contains
archived: false. - Run the call again and choose Approve. The status changes to Draft archived, the button is disabled and the tool returns
{ archived: true }. Reload the page to reset the draft.
If the tool is unavailable, check typeof document.modelContext?.registerTool in the console. If it returns undefined, check the flag and run the demo on localhost or HTTPS.
WebMCP browser support
Browser support checked 1 Dec 2026. WebMCP is a Community Group draft, and document.modelContext needs a secure context. For this demo, use localhost or HTTPS. Chrome deprecated navigator.modelContext in 150 and removed it in 152. Chrome 153 added the callback's abort signal, and Chrome 155 added the object argument used by the console example. Chrome API updates, 26 Nov 2026
- Chrome. The origin trial began in Chrome 149. Its desktop extension is listed through Chrome 162. Chrome Platform Status, updated 25 Nov 2026
- Edge. The origin trial began in Edge 150 and is listed through 30 Mar 2027. Microsoft documents the
about://flags/#enable-webmcp-testingflag for local testing in Edge Canary or Dev. Edge 150 release notes, 2 Jul 2026, Edge origin trial, Microsoft's Edge testing instructions - Firefox and Safari. Mozilla tracks a Firefox prototype. WebKit recorded an opposing standards position on 11 Jun 2026. Mozilla's Firefox prototype, WebKit's standards position
For local calls in a browser without native WebMCP, install @w3c/webmcp-polyfill@0.2.1 and add import "@w3c/webmcp-polyfill/auto" at the top of src/main.tsx. The polyfill lets this page register and call its own tool. A browser agent still needs support for connecting to the page. W3C polyfill, WebMCP implementation status
The pointer follows actions routed through UI SDK's agent bridge. Keep server-side permission checks on a real archive endpoint and tie approval to the specific draft and change. Chrome's tool design guidance, updated 30 Oct 2026
If you're choosing between WebMCP and an MCP server, start with where the tool needs to act. This tool belongs to the page displaying the draft. MCP defines how a client talks to a server over transports such as stdio or Streamable HTTP. MCP transport specification, 25 Nov 2025
How we tested
On 1 Dec 2026, we built the sample with React 19.3.1, Vite 8.4.0, UI SDK 0.1.0-beta.17 and shadcn CLI 4.23.1. Playwright Core 1.63.0 called the tool in headless Chrome 158.0.8127.88 with --enable-features=WebMCP.
The pointer moved to Archive draft and a second call failed while the first Approval was pending. Deny, Take over and caller cancellation left the draft unchanged. After Take over, new calls were blocked until the person let the agent continue. Approve archived the draft. With the flag off, a manual click on the same button still worked.
We repeated the flow with the W3C polyfill in Playwright Firefox 155.0 and Playwright WebKit 26.6. A separate Vite dev run confirmed that React Strict Mode left one registered tool and that unmounting removed it and dismissed a pending approval. The tests used scripted calls in place of a model. The WebKit run used Playwright's engine. Edge, the Safari app and origin trials were outside the test.
Questions
How do I use WebMCP in React?
Register a tool with document.modelContext.registerTool() in a React effect. Pass an AbortSignal and abort it during cleanup to remove the tool when the component unmounts.
What is the WebMCP flag in Chrome?
Enable WebMCP for testing at chrome://flags/#enable-webmcp-testing and relaunch Chrome. On the demo's localhost or HTTPS page, typeof document.modelContext?.registerTool should return function.
What happened to navigator.modelContext?
Chrome deprecated navigator.modelContext in version 150 and removed it in 152. Use document.modelContext for the current WebMCP API.
WebMCP vs MCP: what is the difference?
WebMCP lets a page expose tools that act in that page, such as archiving the draft shown on screen. MCP lets clients connect to servers that expose tools over transports such as stdio or Streamable HTTP.