Vercel's AI SDK Lets Server Models Call Live Browser Tools Directly
Vercel's AI SDK now speaks WebMCP, letting browser-side JavaScript functions act as tools for a server-hosted LLM without shuffling secrets to the client.
Takeaways
- Vercel's AI SDK adds a WebMCP transport so browser-registered tools can be called from a server-side model.
- Model inference stays on the server with
streamText; tool execution runs in the open tab. - New
createMCPToolsconverts browser tool definitions into AI SDK tools without server-side execute functions. - Reference shopping cart example shows registerTool, useChat, and onToolCall wiring end to end.
- Requires Chromium 146+ with the enable-webmcp-testing flag; WebMCP is still a W3C draft.
- Best fit: agents acting on the user's current authenticated session and visible app state.
Vercel has added an experimental WebMCP transport to its AI SDK, allowing a server-hosted model to call tools registered inside an open browser tab. The AI SDK recipe demonstrates the pattern with a shopping cart whose state can be read and changed through chat.
The model request and provider credentials remain on the server, while tool discovery and execution happen in the browser. That division lets an agent work with the page’s current route, JavaScript logic, and authenticated session without requiring a separate Model Context Protocol server for the same actions.
One agent, two runtimes
WebMCP is a proposed browser API that lets pages expose JavaScript functions as structured tools through navigator.modelContext. AI agents, browser assistants, and assistive technologies can discover those tools and invoke them with schema-validated arguments.
The AI SDK transport connects that browser registry to an LLM running through the server-side streamText API. On the server, createMCPTools converts definitions supplied by the browser into AI SDK tools without execution handlers. The model can select those tools, but the browser remains responsible for running them and returning their results.
| Responsibility | Runtime |
|---|---|
| Model credentials and inference | Server |
| Tool registration and discovery | Browser |
| Application state | Browser or existing app services |
| Tool execution | Browser |
| Tool results returned to the model | Browser to server |
Five hops from prompt to cart
Vercel’s reference storefront combines product cards, quantity controls, and a chat interface. Clicking a button or entering requests such as Add two mugs
and Remove the T-shirt
updates the same cart state.
- The page registers
getCart,addToCart,updateCartItem, andremoveFromCartwithnavigator.modelContext.registerTool. Each tool includes a JSON Schema derived from Zod. - The browser creates an MCP client using
Experimental_WebMCPTransportfrom@ai-sdk/mcp. - Before each chat request, the client lists the currently registered tools and sends their definitions with the conversation messages.
- The server converts those definitions with
createMCPToolsand passes the resulting tools tostreamText. - When the model emits a tool call,
useChatpasses it throughonToolCall. The browser client invokes the registered JavaScript function and returns its output throughaddToolOutput.
A read-only cart tool can declare an advisory annotation that helps the model and client classify the operation:
await modelContext.registerTool(
{
name: 'getCart',
description: 'Read the current cart, total in USD, and product catalog.',
inputSchema: z.toJSONSchema(z.object({})),
annotations: { readOnlyHint: true },
execute: async () => getCartSnapshot(read()),
},
{ signal },
);
The readOnlyHint annotation describes expected behavior; it does not enforce access control. Applications still need to authorize every consequential operation.
Rapid consecutive calls also expose a React timing issue. The recipe stores the current cart in both state and a ref, then updates the ref synchronously. Without that ref, a second addToCart call can read stale data before React completes its next render.
Preview access requires a flag
WebMCP remains an Early Preview feature. At the time covered by the recipe, testing requires Chromium 146.0.7672.0 or newer with the #enable-webmcp-testing flag enabled. Chrome users can open chrome://flags/#enable-webmcp-testing and relaunch the browser; other Chromium builds use their corresponding flags page. The flag enables the testing interfaces the transport uses to list and execute registered tools.
The demo route accepts only local requests and removes attachments. Those restrictions reflect the current threat model: tool definitions arrive from a client-controlled environment and must be treated as untrusted input.
Lock down the bridge
- Protect the model route. Require authentication and apply origin and cross-site request forgery controls.
- Allowlist tools. Restrict accepted names and schemas, and cap definition counts, description lengths, and payload sizes.
- Authorize mutations. Recheck permissions when an action reaches a backend, and require confirmation for consequential changes.
- Validate results. Treat browser-returned output as untrusted before adding it to model context, logs, or later tool calls.
Best fit: stateful tabs
Browser-hosted tools work best when an agent needs to act on the page a person already has open. Examples include updating a cart, saving a draft on the active support ticket, changing a selected dashboard object, or creating an issue in the current workspace.
- Single-page applications whose available actions change with the route or current selection.
- Workflows that already hold authenticated session state in the active tab.
- Editors, dashboards, and carts where people and agents share visible state.
- Applications that want matching tool names and schemas across browser and server MCP implementations.
Draft limits remain substantial
WebMCP is a Draft Community Group Report with no listed Firefox or Safari implementation. Its current scope covers tools only. MCP Resources, which expose readable context objects, and Prompts, which package reusable prompt templates, are unavailable through the browser API.
The preview also provides no browser permission prompt when a page registers tools. Applications must supply their own consent, confirmation, and policy layers for discovery and execution. The specification explicitly excludes headless and fully autonomous agents from its intended use cases.
Browser state becomes callable
WebMCP gives the active tab a defined role in an agent system: the server runs the model, while the page exposes and executes actions against live application state. If the proposal matures, teams could remove separate MCP services and duplicated client logic from some workflows. They would still need a server route for model credentials and inference. Vercel’s transport provides an early way to test that architecture without implementing the browser-to-model bridge from scratch.