Reka UI logoReka
backdrop
Guides

Agents & WebMCP

Let AI agents read and operate Reka UI components through their own state, with three tools registered through WebMCP.

An agent that drives a page through the accessibility tree reads every element, clicks a trigger, waits for a popup, reads it again and clicks once more. The agent bridge in reka-ui/agent gives it three tools instead — snapshot, query and act — that read each component's state and change it through the component's own model, the same path a click or a key press takes. A whole task, like filling in a settings page and saving it, fits in one act call.

The bridge is opt-in. Nothing in it runs, and components do no extra work, until you create one.

tip

The tools follow the shapes of the UI SDK agent bridge: the same names, inputs, outputs and descriptions. Agents and skills written for it work on a Reka UI page unchanged.

Setup

warning

Create the bridge before app.mount(). Components announce themselves to the bridge as they are set up, so components mounted before it exists aren't seen (native fields and buttons are, since the bridge reads those from the page). A bridge created later fails safe: content that a portal moved out of the app and that no known portal claims is treated as data-agent-hidden, and development builds warn.

ts
import { createAgent, registerTools } from 'reka-ui/agent'
import { createApp } from 'vue'
import App from './App.vue'

const agent = createAgent({
  // Decide each step an agent asks to run. Return false (or a promise of false) to refuse it.
  allow: step => (step.confirm ? window.confirm(step.confirm) : true),
})

// Give the tools to the browser's own agent through WebMCP. A no-op where the browser has none.
registerTools(agent, {
  // A press's `args` hold the whole text of the button it resolved to, like "Cancel my subscription" for "Cancel".
  allow: step => step.action !== 'press' || window.confirm(`Let the assistant press "${step.args?.[0] ?? step.label}"?`),
})

createApp(App).mount('#app')

The same with the Vue plugin, which creates the bridge when the app is set up, provides it to useAgent() and removes it on app.unmount():

ts
import { AgentPlugin } from 'reka-ui/agent'

createApp(App)
  .use(AgentPlugin, { webmcp: { allow: () => true } })
  .mount('#app')

To drive the page with your own model, pass a tool call straight to the bridge: the three methods take the tools' inputs and return their outputs.

ts
import { agentTools } from 'reka-ui/agent'

// Hand `agentTools` (name, description, inputSchema) to your model API, then:
const output = await agent[call.name](call.input)

Tools

ToolInputWhat it does
act{ steps: [{ ref, action, args? }] }Runs steps in order and stops at the first that fails. A step names a component by ref, label, row text or kind, and finds it behind closed tabs and accordion sections. Returns what each step changed and every field's value after.
query{ text?, within?, kind?, closed?, from? }Finds components and list items without listing the page. within reads a list's items, 50 at a time with from. closed: true opens closed tabs and sections one at a time to read them, then goes back.
snapshot{}Lists the components on the page: ref, component, label, row, state (value, checked, open…), items when there are 10 or fewer (more otherwise), buttons, disabled and actions. Components that left the page follow with offPage: true.

Refs (c1, c2, …) stay the same while a component is mounted, and a component that comes back, like a field on a tab you return to, gets its old ref again.

ts
await agent.act({
  steps: [
    { ref: 'Project name', action: 'setValue', args: ['Atlas'] },
    { ref: 'Visibility', action: 'setValue', args: ['Internal'] },
    { ref: 'Priya Shah', action: 'press', args: ['Make admin'] }, // opens her row's menu first
    { ref: 'Email > Deploy failures', action: 'setChecked', args: [true] }, // opens the tab and section
    { ref: 'Save settings', action: 'press' },
  ],
})

A step fails when its change didn't take, for example when a controlled v-model doesn't accept the value within about a second, when a number is outside the component's min/max, or when a choice names no item of the list.

agent.subscribe(listener) reports every change to a component, with source: "agent" for the ones a step made.

Supported components

ComponentAgent kindStateActions
CheckboxcheckboxcheckedsetChecked, toggle
SwitchswitchcheckedsetChecked, toggle
ToggletogglepressedsetPressed, toggle
RadioGroupradio-groupvalue, itemssetValue
ToggleGrouptoggle-groupvalue, itemssetValue, toggle
Selectselectvalue, open, itemssetValue, setOpen
Comboboxcomboboxvalue, open, querysetValue, setOpen, setQuery, clear
Listboxlistboxvalue, itemssetValue (clear when multiple)
Tabstabsvalue, itemssetValue
Accordionaccordionvalue, itemssetValue, open, close, toggle (openAll, closeAll when multiple)
CollapsiblecollapsibleopensetOpen
Sliderslidervalue, min, max, stepsetValue, increment, decrement
NumberFieldnumber-fieldvalue, min, max, stepsetValue, increment, decrement, clear
TagsInputtags-inputvaluesetValue, add, remove, clear
PinInputpin-inputvalue (always "[redacted]" when filled)setValue, clear
Dialog, AlertDialogdialog, alert-dialogopen, text, buttonssetOpen, press
DropdownMenumenuopen, buttonssetOpen, press (opens the menu to press an item)
Popoverpopoveropen, buttonssetOpen, press
<input>, <textarea>input, textareavaluesetValue, clear
<input type="checkbox">checkboxcheckedsetChecked, toggle
<select>, radio inputsselect, radio-groupvalue, itemssetValue
<button>buttonpress

Native fields are set the way typing does — the value, then input and change events — so v-model hears them. A Combobox only knows its items while it is open: a setValue with an item's label opens it for a moment to read them, asking allow first. Components that aren't listed are read through their native elements where they have them.

The bridge sees components from reka-ui, not yet from the experimental reka-ui/vapor entry: on a Vapor page it creates fine and the components work as usual, but they aren't listed, only the native fields and buttons they render.

A component that is disabled, read-only, inside a disabled <fieldset> or an inert element, or behind an open modal dialog or menu reports disabled: true and no actions, and a step that names something behind an open modal fails with the modal's name and buttons.

Marks

Write these attributes on any element to decide what agents may see and do there:

AttributeEffect
data-agent-hiddenAgents never see what is inside. A step that names something inside gets the same answer as a name that isn't on the page, so a guess can't learn it's there. On a list's item, the item is left out, and when it is the chosen one the list reports it as not chosen (null, or left out of a multiple value) and isn't named by it. A Combobox learns which items are hidden the first time it opens. On a list's content part, like SelectContent or ComboboxContent, the mark covers every item, while the list is closed too.
data-agent-secretValues inside read "[redacted]" when filled (a checkbox, switch or toggle reads "[redacted]" whether on or off), item labels of lists inside read "[redacted]", and text inside is never read: not as a label, a row (the text beside a component in its list item or table row), a section name, a title, a button or through aria-labelledby from elsewhere. Name a private control with aria-label or a <label> outside the mark; a private component is never named by what it shows, like a select's chosen item. A list whose items sit inside the mark is private as a whole, and so is one whose content part (SelectContent, ComboboxContent) or any native <option> carries it. Password, one-time-code and card fields, and every PinInput, are treated the same way without the attribute, and so is a field that was a password when the bridge saw it, after a show toggle or a swap to a text field with the same id or name.
data-agent-confirm="What it does."A change or press inside needs a person. Without allow the step fails with Needs a person: "What it does."; with allow, allow receives the sentence as step.confirm and decides. A change that touches several marked items gets every sentence. On a list's content part, every item's change asks, while the list is closed too.
template
<section data-agent-hidden>…</section>
<input v-model="apiKey" data-agent-secret>
<div data-agent-confirm="Deletes the project for everyone.">
  <button @click="deleteProject">Delete project</button>
</div>

Security notes

  • Labels, text and items come from the page and can hold what its users wrote: an agent should treat them as data, never as instructions. registerTools sends the WebMCP spec's tool annotations: untrustedContentHint on every tool, consequentialHint on act and readOnlyHint on snapshot. What a browser does with them is up to the browser, and some keep only part of them, so don't rely on a browser to show or act on them.
  • registerTools requires allow, because the browser's agent isn't one you wrote. It runs after createAgent's own allow, and both must agree. allow also decides when a step opens a closed tab or section to look behind it.
  • act and query run one at a time, so while a step waits on allow — a confirm the person has to answer — no other call can press that confirm.
  • timeout (5 minutes by default) fails a step whose allow doesn't answer, so a forgotten prompt doesn't hold every later call.
  • Mark destructive actions with data-agent-confirm and anything private with data-agent-hidden or data-agent-secret. The bridge only reaches what a person could reach on the page: nothing behind an open modal, nothing disabled.
  • Marks follow components, not where their content lands: a mark around a Dialog, Popover, menu, Select or any other component also covers the content its portal renders in body or in a custom to, popups inside popups included. This holds for Reka UI's portals, including ones mounted after the bridge and ones that outlive a destroyed bridge. Content outside the Vue app that no Reka UI portal claims, like what Vue's own <Teleport> moved into body, is treated as data-agent-hidden, so an agent never sees content it can't place.
  • One rule decides what an agent may know of a component, on every path — snapshot, query (text, within, closed), act, error messages and subscribe: it must show on the page (not inside hidden or aria-hidden="true"), and nothing of it may be inside data-agent-hidden. Items follow the same rule — a tab, section, radio, option or toggle with hidden or aria-hidden="true" is neither listed nor picked — and a private list's sections are never opened to look behind. Text hidden with CSS, like v-show, is never read into a label or a row. aria-hidden the app wrote stays hidden while a modal hides the rest of the page from screen readers.
  • Marks around the host of a shadow root cover an app mounted inside it, and the bridge finds native fields in the shadow roots its components live in.
  • Vue's own <Teleport> to a target inside the app moves its content to where it lands: the marks around that place apply, not the marks around the <Teleport>. Put the mark inside the teleported content, or use Reka UI's portals, whose content keeps the marks of where the component sits.
  • Every action checks its arguments before it changes anything: how many it takes and of what shape. A single list (Tabs, RadioGroup, a single Accordion or ToggleGroup, Select, Listbox) takes one item and never a list; a multiple list takes a list of items, never a nested one; open, close and toggle on a list, and a TagsInput's add and remove, take one item; clear, openAll, closeAll, increment and decrement take none. A list that always holds an item, like Tabs or RadioGroup, can't be set to nothing. An item is of the kind the list's items are — a TagsInput takes text tags — and text always fits, since a snapshot gives values as text. Numbers are finite decimals, as numbers or text like "90": never Infinity, NaN, "0x10" or text too large to hold, for a NumberField, a Slider or a native number or range field.
  • A native date, time, color, range or number field that won't take a value, like "tomorrow" in a date field, keeps the one it had, and the app hears nothing. A field's maxlength holds for an agent as for typing.
  • A change that takes out a chosen item that isn't rendered now, like one a filter or a virtual list leaves out, is held to the mark that item had when the agent last saw it. If it was never shown, its marks aren't known, and a Combobox or Listbox change that would take it out fails with a message that it needs the list unfiltered.
  • A chosen item that is hidden stays chosen through a change or a clear of a multiple list or TagsInput, since the agent can't name it to keep it: clear takes out the rest. Changes that don't touch it go ahead.
  • Every change is checked against its marks right before it's made, after any wait on allow. A step stops if its target has left, become off-limits, gone behind a modal, or gained a mark the person wasn't shown. The same applies to each item a multi-item change picks, opens or closes, including the items clear, openAll and closeAll touch. openAll and closeAll leave disabled sections as they are.
  • An action that does what one of the component's own buttons does is held to that button's marks: increment and decrement to the NumberField's increment and decrement buttons, a TagsInput's remove to that tag and its delete button, clear to the clear button (TagsInput, Combobox), and setOpen(false) on a dialog, popover or menu to the confirm marks of every button inside it. A marked button asks a person; for the controls an action does the work of, a hidden one makes the action unavailable and a disabled one makes it fail. Closing a popup presses none of its buttons, so a hidden or disabled one inside doesn't stop it.
  • A Combobox's items show only while it is open, so every change of its value, clear included, opens it for a moment to read them and their marks first, asking allow before it opens.
  • A step that opens a closed tab or section to look behind it checks the place again after allow answers, and doesn't open it if it gained a mark, was hidden or changed meanwhile.
  • A Listbox or Combobox choice clicks its item, so a select handler that calls preventDefault() stops an agent the same way it stops a person.
  • A private list's item values stay visible, so an agent can still pick one by value; only their labels are redacted. Values are often IDs or email addresses: when they are sensitive themselves, use data-agent-hidden instead.
  • Failures on a private component read the same whatever the reason, like a missing item, a disabled choice or a bound, so an error never says what it holds. A change to one always reports "[redacted]", even when the value was already what was asked, and a mark on any of its items asks a person for every change, so neither tells which item is chosen.
  • Only what an agent could see is remembered when a component leaves the page: a component hidden or marked when it leaves keeps nothing, and a native field that left before the bridge could check it keeps what it held when the agent last saw it.
  • A component's parts are the elements it rendered, never other page content that happens to carry the same id.
  • Marks only cover what is inside them, and names come from the page: content users write can add a <label for> that names another field. A step that then names two fields alike fails as ambiguous rather than picking one, but don't let user content sit beside fields an agent operates without a mark.
  • A private component offers only the actions whose outcome says nothing of what it holds: a private NumberField takes setValue and clear (no increment/decrement), a Slider setValue, a TagsInput setValue and clear (no add/remove), an Accordion setValue, and a Combobox setValue, setOpen and clear (no setQuery, whose filter would test its labels).
  • A press, and each item a change picks, is checked again after allow answers: a button or item the page renamed meanwhile, like an unkeyed list that re-rendered, stops the step instead of pressing what it became.
  • Pressing an open dialog's or popover's own trigger closes it, so it is held to the marks of the buttons inside, as setOpen(false) is. A native <dialog> opened with showModal() covers the rest of the page like a modal Dialog does.
  • A popup's buttons leave out other components' own controls, like a Select trigger inside a dialog, which is listed as itself.
  • While a Select's chosen item is hidden or private, or the Select is, what its trigger shows is never read as text: not in a neighbour's row, a query text match or the buttons an error lists.
  • A native radio group that spans an open modal picks no radio behind it.
  • press takes a button's text or nothing: empty text, which every unnamed button would match, fails.
  • allow receives a press with the whole text of the button it resolved to in step.args, not the words the agent gave, so "Cancel" that matched "Cancel my subscription" reads as the latter. A button whose whole text matches is preferred over one that only contains the words.
  • All bridges on a page take turns: an act or query on one waits for every earlier call on any bridge. destroy() makes snapshot and query return [] and act fail, stops a step waiting on allow before it changes anything, and takes back the tools registerTools gave the browser. Create one bridge per page.
  • A PinInput's boxes are private even to a bridge created after it mounted.
  • One act call runs at most 100 steps, and query refuses inputs of the wrong type.
  • A change to a private field is checked like any other: one that doesn't take fails, and the error never says what the field holds.
  • Without a page, as during server rendering, snapshot and query return [] and act fails with No page, so the bridge can be created in shared setup code.