WebMCP
Hand the calendar's tools to the agent built into a browser, with rules of their own for an agent you didn't write.
WebMCP lets a page offer tools to the agent built into a browser, through
document.modelContext. registerTools from @ui-sdk/solid/agent registers the bridge's three
tools there, and a browser's agent can then read your calendar and change it without any server of
yours in between.
WebMCP is new, and most browsers don't have it yet. In one without it, registerTools does
nothing, so calling it is safe everywhere.
This page uses the bridge in agent.ts from Connect an agent.
Register the tools
Call registerTools once, in the browser, with the bridge and an allow:
import { registerTools } from "@ui-sdk/solid/agent";
import { agent } from "./agent";
/**
* Hands `snapshot`, `act` and `query` to the browser's own agent. Does nothing in a browser
* without WebMCP. Returns the function that takes the tools back.
*/
export function registerCalendarTools(): () => void {
return registerTools(agent, {
// The browser's agent isn't one you wrote, so it gets an answer of its own for every step,
// after the bridge's `allow`. Here it may navigate and edit, and never delete.
allow: ({ action, component, confirm }) =>
component === "calendar" &&
confirm === undefined &&
action !== "deleteEvent" &&
action !== "setTimeZone",
});
}
/** Whether this browser takes tools from a page. */
export function hasWebMcp(): boolean {
const context = (globalThis.document as { modelContext?: { registerTool?: unknown } } | undefined)
?.modelContext;
return typeof context?.registerTool === "function";
}Call registerCalendarTools() when your app starts, or when the person turns the feature on. It
returns the function that takes the tools back:
import { onSettled } from "solid-js";
import { registerCalendarTools } from "./agent-webmcp";
/** Offers the tools to the browser's agent while this component is on the page. */
export function WebMcpTools() {
// In the browser, once the component is on the page. The function `registerCalendarTools`
// returns takes the tools back when the component leaves.
onSettled(() => registerCalendarTools());
return null;
}The browser's agent gets three tools:
| Tool | What it does | Hints the browser gets |
|---|---|---|
snapshot | Lists the page's components, your calendar among them | readOnlyHint, untrustedContentHint |
query | Finds components, or the events one calendar shows | readOnlyHint, untrustedContentHint |
act | Runs steps, such as moveEvent | consequentialHint, untrustedContentHint |
The tools are the bridge's own, with the descriptions ui-sdk wrote for models. They aren't calendar-specific: the agent learns the calendar's actions from the snapshot, where the entry lists them by name.
The names are all the tools can tell it. act's definition doesn't say what moveEvent takes, and
you can't add to a browser agent's prompt. The calendar says it in two places. Its
describeCalendar action returns each action with its input. And an agent that guesses gets the
input spelled out in the failed step, which is enough to correct the next call:
calendar-agent-invalid-arguments: moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it takes one object, not 2 argumentsAn allow of its own
You didn't write the browser's agent, and it acts for whoever is using the browser. So
registerTools takes an allow of its own, apart from the bridge's:
- The bridge's
allowfromcreateAgent, when it has one. - The
allowyou pass toregisterTools. - Your policies, then
onEventChange.
A step runs when all of them let it. The one above lets the browser's agent read, navigate and
change events, and never delete or change the time zone. A refused step fails with
The app refused setTimeZone on c1.
deleteEvent is on that list for the calendars that turn deleting on. On
any other calendar the action doesn't exist, and the step fails before allow is asked.
confirm === undefined in the example leaves out any step on a control you marked with
data-agent-confirm, which is ui-sdk's mark for a control a person must press. The calendar has
no such controls of its own; the check keeps the rule for the other ui-sdk components on your page,
which the same three tools reach.
Detect WebMCP
hasWebMcp() in the file above checks for the registration function, so you can show the feature
only where it works:
typeof document.modelContext?.registerTool === "function";TypeScript's DOM types don't have modelContext yet, which is why the helper reads it through a
cast.
What the browser's agent reads
Everything the tools return is page content: event titles, labels, the calendar's title, and what
listEvents and describeCalendar return. A title is text somebody typed, and it may say "ignore
your instructions". The tools carry
untrustedContentHint so the browser treats their results as data. Your part is the same as for
any agent:
- Keep what the agent shouldn't read out of the snapshot, with
data-agent-hidden. - Decide by action in
allow, not by trusting what the agent says it wants. - Keep deletes off, or behind a question.
Try it
- In a browser with WebMCP, open your app and look for
snapshot,queryandactamong the page's tools. - Ask the agent to read first: "Which meetings are on the team calendar this week?"
- Then to change something: "Move the design review to Friday at 10."
The ui-sdk documentation at ui-sdk.dev/docs has a walkthrough for a browser that supports WebMCP today.