---
title: "WebMCP"
description: "Offer your app's actions to AI agents in the browser, as WebMCP tools."
canonical_url: "https://nuxt.com/docs/4.x/guide/ai/webmcp"
---
# WebMCP

> Offer your app's actions to AI agents in the browser, as WebMCP tools.

[WebMCP](https://webmachinelearning.github.io/webmcp/) is a proposed browser API that lets a page offer tools to AI agents running in the browser, so an agent can add something to a cart or submit a form without guessing which button to click. Nuxt can turn the actions your templates already bind into WebMCP tools.

::important
This is an experimental feature, built on an API that is still being designed. Tools register only in [browsers that support WebMCP](#browser-support).
::

Enable it in your `nuxt.config`:

```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
  experimental: {
    webmcp: true,
  },
})
```

## Tools from Templates

Tag a function with `@tool` in its JSDoc and bind it to `@click` or `@submit` on an element, or to an event on a component. Nuxt registers a tool named after the function, described by the JSDoc summary:

```vue [app/pages/index.vue]
<script setup lang="ts">
const { data: products } = await useFetch('/api/products')
const cart = useCart()

/**
 * Add one of a product to the cart. Use when the user wants to buy something.
 * @tool
 */
function addToCart (sku: string) {
  cart.value.push(sku)
}
</script>

<template>
  <ul>
    <li
      v-for="product in products"
      :key="product.sku"
    >
      {{ product.name }}
      <button
        :disabled="!product.inStock"
        @click="addToCart(product.sku)"
      >
        Add
      </button>
    </li>
  </ul>
</template>
```

This registers an `add_to_cart` tool, and:

- the arguments come from the template, so the agent cannot pass a SKU that is not on the page;
- inside a `v-for`, the agent picks an item by its `:key` as `target`, and a shared `list_targets` tool lists the items on screen with their text;
- `:disabled` controls whether the tool, or one of its targets, can run;
- a call runs the bound expression, and its return value is the tool result.

Write descriptions for the agent: say what the tool does for the user and when to use it, and leave implementation details out.

Flags after `@tool` describe the action:

| Flag            | Meaning                                                                                                                                                     |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `readonly`      | The tool only reads, so an agent can call it freely.                                                                                                        |
| `consequential` | The tool has effects that are hard to undo, so the browser or agent may ask the user first.                                                                 |
| `confirm`       | The user must complete the action. A call highlights the control (or fills in the form) and returns `status: "requires_user_action"` instead of running it. |
| `values`        | For a form, the current values of its fields are sent to the agent as defaults. See [What a Call Can Read and Change](#what-a-call-can-read-and-change).    |

```ts
/**
 * Place the order for everything in the cart. Use when the user is ready to pay.
 * @tool consequential
 */
function checkout () {}
```

## Forms

A `@tool` function bound to `@submit` becomes a form tool. Its input is the form's `v-model` bindings, and a call writes them, then submits the form, so your own validation and submit handler run as they would for the user. Fields whose `v-model` reads a `v-for` or slot variable declared inside the form are not part of the input.

Pass a [Standard Schema](https://standardschema.dev) (such as Zod, Valibot or ArkType) with `@input`, or bind it to the form as `:schema`, to validate the input. A schema that implements Standard JSON Schema, such as a Zod schema, or a Valibot schema wrapped in `toStandardJsonSchema()` from `@valibot/to-json-schema`, also describes the input to the agent. Otherwise, types come from the current values and the native controls. Labels become descriptions.

```vue [app/pages/contact.vue]
<script setup lang="ts">
import { z } from 'zod'

const contactSchema = z.object({
  email: z.email(),
  message: z.string().min(5),
})
const form = reactive({ email: '', message: '' })

/**
 * Send a message to the shop. Use when the user has a question about an order.
 * @tool
 * @input contactSchema
 */
async function sendMessage () {
  await $fetch('/api/contact', { method: 'POST', body: form })
  return 'Sent.'
}
</script>

<template>
  <form @submit.prevent="sendMessage">
    <label>Email <input
      v-model="form.email"
      type="email"
    ></label>
    <label>Message <textarea v-model="form.message" /></label>
    <button type="submit">
      Send
    </button>
  </form>
</template>
```

Input is checked against the schema before anything is written. Native constraints, such as `required` or `type="email"`, are checked once the values are written, and a call that fails them restores the form.

### What a Call Can Read and Change

A form tool only fills in a field that the browser reports as rendered and that is not disabled or read-only. A call that provides a value for any other field is rejected.

A field is rendered when the element with its `v-model` is displayed. That excludes a field removed by `v-if`, an `<input type="hidden">`, and a field that is hidden, or inside an element that is hidden, with `v-show`, the `hidden` attribute, `display: none`, `visibility: hidden`, `opacity: 0` or a closed `<details>`, whether that comes from your template or from a stylesheet. A checkbox or radio button that is hidden behind its own visible `<label>` counts as rendered.

A rendered field is still rejected when it is:

- disabled, with the `disabled` attribute, a disabled `<fieldset>`, `aria-disabled="true"` or `data-disabled`
- read-only, with the `readonly` attribute or `aria-readonly="true"`
- inside an element with the `inert` attribute
- a component whose `disabled` or `readonly` prop, written on it in the template, is true
- a disabled `<option>`, radio button or checkbox
- a value that none of the options offers, leaving out any `<option>` or `<optgroup>` that is hidden with the `hidden` attribute or `display: none`

A value that repeats the default published for a disabled or read-only field is accepted while the field still has that value.

The current values of a form's fields are not sent to the agent. Add the `values` flag to publish them as defaults, so the agent can read what is already filled in:

```ts
/**
 * Save the profile. Use when the user wants to change their details.
 * @tool values
 */
function saveProfile () {}
```

With `values`, the current value of a field is still left out when:

- the field is not rendered
- the field has `type="password"`
- the field's `autocomplete` is `current-password`, `new-password`, `one-time-code` or a payment card value such as `cc-number`
- your schema marks the property, or an object that contains it, as `writeOnly`

Defaults are read when the form mounts, so a field that is hidden afterwards keeps the default it was published with.

For a component, whether it is rendered is read from the element that receives the component's attributes. The other attributes are read from that element and from the first native control inside it.

::warning
Some restrictions are not detected:

- A field that is moved off-screen, clipped or covered by another element counts as rendered.
- A component that hides its own control while the element around it stays displayed counts as rendered.
- A default that your schema declares for a property is published as written, whatever the field. Keep secrets out of schema defaults.
- With `values`, a secret in a field that has none of the signals above is published as a default. Give it `type="password"`, a matching `autocomplete`, or a `writeOnly` property in your schema.
- A component that is disabled in another way, such as through `v-bind` with an object or from inside the component, is treated as editable unless the element it renders has one of the attributes above.
- A component that does not render its attributes on an element cannot be filled in.

These checks keep an agent to what the page offers the user. Validate and authorize every submission on the server, as you would for any other request.
::

## Tools from Code

For tools that do not map to one control, define a tool with `defineAgentTool()` and offer it while a component is mounted with `useAgentTool()`:

```vue [app/components/ProductSearch.vue]
<script setup lang="ts">
import { z } from 'zod'

const searchProducts = defineAgentTool({
  name: 'search_products',
  description: 'Find products by name. Use when the user asks what is for sale.',
  input: z.object({ query: z.string() }),
  annotations: { readOnlyHint: true },
  execute: ({ query }, { signal }) => $fetch('/api/products', { query: { q: query }, signal }),
})

useAgentTool(searchProducts)
</script>
```

`input` validates each call, and describes the tool's parameters when the schema implements Standard JSON Schema. For other schemas, describe the parameters with `inputSchema`.

Pass `targets` (with `key` and `label`) to let the agent choose between items, and `enabled` to make the tool unavailable without unregistering it. The agent chooses an item with an argument named `target`, so a tool with `targets` cannot have an input property of that name.

## Showing What the Agent Does

`useAgentActivity()` returns the tool calls in progress, so you can show the user what an agent is doing and let them stop it. Stopping a call aborts the `signal` passed to `execute`, and the agent receives a result asking it not to retry. A `@tool` function runs as the event handler it is bound to and does not receive a `signal`: a form tool stopped before it submits restores the form, and a handler that has started runs to completion.

```vue [app/components/AgentStatus.vue]
<script setup lang="ts">
const { current, stop } = useAgentActivity()
</script>

<template>
  <p v-if="current">
    {{ current.message }}
    <button @click="stop">
      Stop
    </button>
  </p>
</template>
```

## Navigation

Nuxt also registers a `navigate` tool listing your app's pages, so an agent can reach actions on other pages. Tools are swapped when the page changes. Disable it with `navigate: false`:

```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
  experimental: {
    webmcp: { navigate: false },
  },
})
```

## Development

Nuxt warns at build time about bindings that cannot become tools (such as handlers that wrap a `@tool` function, or a `v-for` keyed by its index), descriptions that do not follow the [WebMCP tool design guidance](https://github.com/GoogleChromeLabs/webmcp-tools), and form fields without a label. In development, it also warns about tools and results that are longer than agents handle well.

While `nuxt dev` runs with the Vite builder, every tool your pages offer as you browse is written to `.nuxt/webmcp/schema.json`, with the tools seen on each page. This works in any browser. You can use it with [`webmcp-evals`](https://github.com/GoogleChromeLabs/webmcp-tools/tree/main/webmcp-evals) to check that a model picks the right tools. Set `schema` to write it somewhere else, or `false` to turn it off:

```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
  experimental: {
    webmcp: { schema: 'webmcp.schema.json' },
  },
})
```

## Browser Support

WebMCP is in early preview in Chrome and is not turned on by default. Where it is unavailable, no tools register and your app behaves as it does without this feature.

To try your tools locally, turn on `chrome://flags/#enable-webmcp-testing` in Chrome, or start it with `--enable-features=WebMCP`, and open your app on `localhost`, as WebMCP requires a secure context. You also need an agent that calls WebMCP tools, such as the [Model Context Tool Inspector](https://chromewebstore.google.com/detail/model-context-tool-inspec/gbpdfapgefenggkahomfgkhfehlcenpd) extension.

To offer tools to your users, [register your site for the WebMCP origin trial](https://developer.chrome.com/origintrials/#/register_trial/4163014905550602241) and add the token to your pages:

```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
  app: {
    head: {
      meta: [
        { 'http-equiv': 'origin-trial', 'content': 'YOUR_ORIGIN_TRIAL_TOKEN' },
      ],
    },
  },
})
```

A token is tied to the origin it was registered for and expires, so other origins, such as staging or preview deployments, need their own.


## Sitemap

See the full [sitemap](https://nuxt.com/sitemap.md) for all pages.
