WebMCP

Expose your frontend tools to any compatible browser agent on your site, one tool at a time or all of them with one setting.

Overview

Browser agents that visit your site have to guess which buttons to click. WebMCP lets your site tell them what they can do. The agent discovers a named tool with a description, a typed input schema, and a JavaScript handler.

With CopilotKit, a frontend tool you define can also be a WebMCP tool. Your own agent can call it. Any compatible browser agent that visits your site can call it too.

CopilotKit publishes the tool to document.modelContext. The same handler runs for your agent and for browser agents. You write the tool once.

WebMCP is experimental

WebMCP is a draft Community Group report, not a W3C Standard. Chrome offers it through an origin trial beginning in Chrome 149, or through the chrome://flags/#enable-webmcp-testing flag for local development. CopilotKit safely does nothing when document.modelContext is unavailable. Check the current Chrome setup instructions before testing.

Start with your coding agent

Use this pre-built prompt to add WebMCP to your project. Your coding agent will adapt the implementation to your app and verify that a compatible browser can discover and call the tool.

Open your coding agent in your project's folder, or in an empty folder for a new app.

Choose what to expose

WebMCP is off until you turn it on. You have two choices:

  • One tool at a time: add webmcp: true to each tool. See Expose one tool.
  • Every tool: set defaultWebMCPTools on the provider. Every tool you define is then available to all agents that visit your site, not only to your own agent. See Expose every tool.

A tool's own webmcp value always wins over defaultWebMCPTools.

What defaultWebMCPTools exposes

When defaultWebMCPTools is on, CopilotKit registers a frontend tool with WebMCP when all of these are true:

  • The tool has a handler.
  • The tool has a non-empty description. WebMCP rejects tools without one.
  • The tool is available. A tool with available: false is removed from WebMCP until it is available again.
  • The tool does not set webmcp: false.

These tools are not included:

  • Human-in-the-loop tools. Their handler waits for a response from UI in your chat, and a browser agent never sees that UI.
  • Render-only tools. A tool with no handler has nothing for a browser agent to run.
  • CopilotKit's built-in tools, such as the tool for Open Generative UI.

Do not set webmcp: true on a human-in-the-loop tool. The browser agent waits for a response that never comes. CopilotKit's built-in tools always stay private.

Do I need an agent?

You do not need a CopilotKit backend agent to handle a WebMCP call. A compatible browser agent calls the frontend tool handler directly on the page. In that path, the handler context has no agent.

Choose the smallest path that fits your app:

What your app has todayWhat to do
A CopilotKit frontend tool for the actionAdd webmcp: true to it, or turn on defaultWebMCPTools.
CopilotKit, but no frontend tool for the actionWrap the smallest suitable browser-side action in a frontend tool.
A backend agentKeep it. The tool stays available to that agent, but WebMCP calls do not pass through it.
No backend agentUse CopilotKitCore directly in browser code, or add the appropriate frontend integration. Do not create an agent only for WebMCP.

React Native does not expose document.modelContext, so WebMCP registration is a no-op there. CopilotKit supports WebMCP in its browser integrations for React, Vue, Angular, and direct core usage.

How CopilotKit connects WebMCP

  1. Your app registers a CopilotKit frontend tool that sets webmcp: true or webmcp: { annotations }, or defaultWebMCPTools is on.
  2. CopilotKit mirrors the tool's name, description, JSON Schema, annotations, and handler onto document.modelContext.
  3. A compatible browser agent discovers the tool and calls the same JavaScript handler while the page is open.
  4. CopilotKit unregisters the WebMCP tool when the frontend tool is removed or becomes unavailable, and unregisters all tools when the provider unmounts.

The WebMCP call stays in the browser unless your handler calls an API. CopilotKit does not route that call through a Runtime or backend agent.

Expose one tool

Add webmcp: true to the frontend tool. To tell browser agents how to treat the tool, pass annotations instead. For example, readOnlyHint: true says that the tool does not change anything.

React frontend tool

This code must run inside your existing CopilotKitProvider.

OrderSearch.tsx
"use client";

import { useFrontendTool } from "@copilotkit/react-core/v2";
import { z } from "zod";

export function OrderSearch() {
  useFrontendTool({
    name: "searchOrders",
    description: "Search the signed-in user's orders by status",
    parameters: z.object({
      status: z.enum(["open", "shipped", "delivered"]),
    }),
    handler: async ({ status }) => {
      const orders = await searchOrders(status);
      return JSON.stringify(orders);
    },
    webmcp: {
      annotations: {
        readOnlyHint: true,
      },
    },
  });

  return null;
}

The React API is documented in useFrontendTool.

WebMCP only, with no agent

For browser code that does not use a framework provider, register the frontend tool directly with the core. Keep the core instance alive for as long as the tool must stay available.

webmcp.ts
import { CopilotKitCore } from "@copilotkit/core";
import { z } from "zod";

export const copilotkit = new CopilotKitCore({
  tools: [
    {
      name: "searchOrders",
      description: "Search the signed-in user's orders by status",
      parameters: z.object({
        status: z.enum(["open", "shipped", "delivered"]),
      }),
      handler: async ({ status }) => {
        const orders = await searchOrders(status);
        return JSON.stringify(orders);
      },
      webmcp: {
        annotations: {
          readOnlyHint: true,
        },
      },
    },
  ],
});

This path does not configure a Runtime or an agent. It only registers browser-side tools through the core. Call copilotkit.stopWebMCP() to unregister all of them, and copilotkit.startWebMCP() to register them again.

Expose every tool

Set defaultWebMCPTools on the provider. Every tool that has a handler and a description becomes a WebMCP tool. See What defaultWebMCPTools exposes.

Before you turn it on, make sure that every handler checks its own authorization. Any browser agent on the page can then call every exposed tool.

layout.tsx
<CopilotKitProvider runtimeUrl="/api/copilotkit" defaultWebMCPTools>
  {children}
</CopilotKitProvider>

For direct core usage, pass defaultWebMCPTools: true to new CopilotKitCore(). To change it later, call copilotkit.setDefaultWebMCPTools(false) or copilotkit.setDefaultWebMCPTools(true).

Keep one tool private

Some tools must stay with your own agent. For example, a tool that deletes data can rely on your chat to ask the user first. A browser agent calls the handler directly and skips that step.

Add webmcp: false to the tool. The tool stays available to your own agent.

DeleteOrder.tsx
import { useFrontendTool } from "@copilotkit/react-core/v2";
import { z } from "zod";

export function DeleteOrder() {
  useFrontendTool({
    name: "deleteOrder",
    description: "Delete one of the signed-in user's orders",
    parameters: z.object({ orderId: z.string() }),
    handler: async ({ orderId }) => {
      await deleteOrder(orderId);
      return "Deleted";
    },
    webmcp: false,
  });

  return null;
}

The option is the same for Vue useFrontendTool, Angular registerFrontendTool, and core tools.

Design tools agents can use reliably

Required:

  • Give every tool a non-empty, specific description. CopilotKit does not register a tool with WebMCP without one.
  • Use readOnlyHint: true only when the handler cannot change state.
  • Set the frontend tool to unavailable when the action cannot run now. CopilotKit removes it from WebMCP until it is available again.

For better results:

  • Keep each tool focused on one action, and give every parameter a useful description.
  • Use untrustedContentHint: true when results can contain user-generated or external content.
  • Return concise, structured results that tell the caller what happened.

For more, see Chrome's WebMCP best practices.

Protect every handler

Any compatible browser agent on your page can call an exposed tool. Annotations are hints, not security controls. Enforce authentication, authorization, validation, rate limits, and user confirmation inside the handler or the API that it calls. See Chrome's WebMCP tool security guidance.

Agent scope does not scope WebMCP

agentId limits which CopilotKit agent receives a frontend tool. WebMCP tools are page-level, so agentId does not restrict browser-agent access. If multiple tools share a name across agent IDs, CopilotKit exposes only one. A tool that opts in with webmcp: true or webmcp: { annotations } wins over one that only follows defaultWebMCPTools. Otherwise, the first one wins. webmcp: false keeps only that tool private. Another eligible tool with the same name is still exposed.

Test the complete path

Set up the browser:

  1. Open Chrome 149 or newer and enable the WebMCP origin trial or local testing flag.
  2. Load the app in an origin-isolated document. The tools permissions policy defaults to self. Cross-origin iframes also need allow="tools".
  3. Make sure that document.modelContext exists.

Test the tool:

  1. Open Chrome's Model Context Tool Inspector.
  2. Make sure that your tool names and schemas appear.
  3. Call a tool with representative inputs and read its result.
  4. Ask the inspector's agent to complete the user task in natural language.
  5. Make sure that the agent chooses the right tool, and that authentication and confirmation boundaries still hold.

If a tool does not appear, make sure that:

  1. The browser setup is complete.
  2. The tool has a description.
  3. The tool is available.
  4. The tool sets webmcp: true, or defaultWebMCPTools is on and the tool is in its set.

When your tools appear in the inspector and its agent can call them, your site works with any WebMCP-aware browser agent.

How is this guide?