Skip to content
Home JavaScript WebMCP — Serverless AI Tool Calls in the Browser

WebMCP — Serverless AI Tool Calls in the Browser

Where developers are forged. · Structured learning · Free forever.
📍 Part of: Advanced JS → Topic 21 of 27
WebMCP is a W3C proposal from Google and Microsoft that lets AI agents call JavaScript functions directly in live pages — no separate server needed.
🔥 Advanced — solid JavaScript foundation required
In this tutorial, you'll learn
WebMCP is a W3C proposal from Google and Microsoft that lets AI agents call JavaScript functions directly in live pages — no separate server needed.
  • WebMCP is a W3C proposal co-developed by Google, Microsoft, and W3C — not yet a stable standard.
  • Tools are JavaScript functions registered on your page via navigator.mcp.registerTool().
  • Unlike backend MCP, WebMCP tools run in the live browser page — the user sees changes in real time.
✦ Plain-English analogy ✦ Real code with output ✦ Interview questions
Quick Answer

Think of WebMCP as giving an AI assistant a remote control for your website. Instead of the AI fumbling through UI clicks blindly, it calls structured JavaScript functions you define — so it can filter products, submit forms, or update the UI directly inside your running page, while you stay in control and watch it happen live.

WebMCP is a W3C Web Machine Learning Working Group proposal co-developed by Google, Microsoft, and W3C. It defines a standard way for web pages to expose JavaScript-based tools that AI agents can call directly in the browser context — without a separate server, without custom middleware, and without breaking the user's live UI.

The key distinction from backend MCP: WebMCP tools run inside the running page. The user sees changes happen in real time. The human stays in the loop. This makes WebMCP ideal for human-in-the-loop workflows where an AI agent assists — rather than replaces — the user.

Setting Up the WebMCP Server Architecture

A WebMCP server typically operates over an HTTP transport layer using Server-Sent Events (SSE) for real-time communication. This allows the AI client to maintain a persistent connection to the server's toolset. We will implement a basic server structure that follows the standard protocol handshake.

The 4-step WebMCP flow works entirely inside the browser: the page loads as usual, the cloud LLM communicates with a browser-integrated agent, the agent uses the WebMCP JS API to call JavaScript functions in the live page, and those functions can update the UI or make HTTP calls to third-party services.

webmcp-register-tools.js · JAVASCRIPT
123456789101112131415161718192021
// Register tools on your page that the AI agent can call
navigator.mcp.registerTool({
  name: 'filter_products',
  description: 'Filter the product list by category and price range',
  parameters: {
    type: 'object',
    properties: {
      category: { type: 'string', description: 'Product category' },
      maxPrice: { type: 'number', description: 'Maximum price in USD' }
    },
    required: ['category']
  },
  handler: async ({ category, maxPrice }) => {
    // This runs directly in your live page context
    const products = await fetchProducts({ category, maxPrice });
    renderProductGrid(products);  // updates UI immediately
    return { count: products.length, category };
  }
});

console.log('WebMCP tools registered — AI agent can now use filter_products');
▶ Output
WebMCP tools registered — AI agent can now use filter_products
⚠ Still a W3C Proposal
WebMCP is an early-stage specification. The navigator.mcp API is not yet available in stable browsers. Follow the W3C Web Machine Learning Working Group for ratification status before using in production.
WebMCP Browser Architecture Flow (Full Detail) Complete architecture showing 4 steps: Browser loads page, LLM in cloud communicates with browser-integrated agent, agent uses WebMCP JS to execute JavaScript functions in page context, WebMCP functions update UI and call HTTP APIs. WebMCP Browser Architecture Co-developed by Google, Microsoft & W3C — AI agents interact via JavaScript AI Platform LLM in the cloud (Claude, GPT, Gemini…) WEB BROWSER Browser Agent Mediates AI ↔ page navigator.modelContext WebMCP JS Running Page Context <index.html / App.tsx> Third-party Service APIs & Services 2 LLM communicates with browser-backed agent 3 Agent uses WebMCP API to execute JS functions directly in the running page context 4 WebMCP functions update UI & call HTTP APIs W3C Web Machine Learning Working Group Proposal THECODEFORGE.IO
Detailed WebMCP Architecture: From LLM Intent to Browser-Native API Execution.
thecodeforge.io
Webmcp Ai Tool Integration

Exposing Tools to the AI Client

Tools are the core of WebMCP. They represent JavaScript functions registered on your page that the AI agent can discover and call. Unlike backend MCP which requires a separate server process, WebMCP tools live in your page's JavaScript context — meaning they have direct access to your DOM, your app state, and your existing frontend code.

This is the fundamental difference from backend MCP: when a WebMCP tool runs, the user sees the result immediately in the live UI. No separate agent-provided interface. No manual wiring. The human stays in control and in the loop.

webmcp-tool-schema.js · JAVASCRIPT
12345678910111213141516171819202122
// Tool definitions follow JSON Schema — same pattern as backend MCP
// but handler runs in-browser, not on a server

navigator.mcp.registerTool({
  name: 'calculate_revenue_projection',
  description: 'Calculates quarterly growth and updates the dashboard chart',
  parameters: {
    type: 'object',
    properties: {
      current_arr:  { type: 'number', description: 'Current Annual Recurring Revenue' },
      growth_rate:  { type: 'number', description: 'Expected quarterly growth rate (0-1)' }
    },
    required: ['current_arr']
  },
  handler: async ({ current_arr, growth_rate = 0.1 }) => {
    const q1 = current_arr * (1 + growth_rate);
    const q2 = q1 * (1 + growth_rate);
    // Update the live chart in the page
    window.revenueChart.update([current_arr, q1, q2]);
    return { q1: q1.toFixed(2), q2: q2.toFixed(2) };
  }
});
▶ Output
// AI agent calls the tool → chart updates live in the browser
// User sees the revenue projection rendered immediately
🔥Schema Integrity
The more descriptive your tool descriptions and parameter schemas are, the more accurately the LLM will select and use them. Write descriptions as if explaining to a junior developer what the function does and when to call it.
WebMCP vs Backend MCP Comparison Side-by-side comparison of WebMCP (browser-native, JS tools in page) vs traditional Backend MCP (server-side MCP server, no UI by default). WebMCP keeps the user in control with live UI updates; backend MCP requires the agent to provide its own UI. WebMCP vs Backend MCP Browser-native tool integration vs traditional server-side MCP ✓ WebMCP Browser-native · JS tools · UI stays live AI Platform LLM in the cloud WEB BROWSER Browser Agent Human in the loop WebMCP JS Exposes JS functions as AI tools in page <index.html> live ✓ User sees live UI changes as they happen Agent acts on the real running page — no separate UI needed Third-party Service (example.com) via HTTP ✗ Backend MCP Server-side · No UI by default · Manual wiring AI Platform LLM in the cloud Agent Frontends web/app — wired manually WEB BROWSER Browser-integrated agent (passive — no WebMCP JS) <index.html> MCP Server Separate process Agent interacts directly example.com ✗ No automatic UI — must be provided by agent Agent-service interaction takes place without an associated UI HTTP ✓ Live UI ✓ Human in loop ✓ JS native ✓ No server needed ✗ No UI ✗ Manual wiring ✗ Extra server ✗ Agent provides UI THECODEFORGE.IO
thecodeforge.io
WebMCP (browser-native) vs Backend MCP (server-side) — Architecture Comparison
Webmcp Ai Tool Integration
FeatureWebMCP (Browser)Backend MCP (Server)Standard REST API
Where tools runInside live browser pageSeparate server processServer endpoint
UI integration✅ Live page updates❌ Agent provides own UI❌ No awareness
Human in loop✅ User sees changes live⚠️ Manual wiring needed❌ None
Tool discovery✅ Auto via navigator.mcp✅ Auto via tools/list❌ Manual (Swagger)
Setup requiredJS in your page onlySeparate MCP serverREST endpoints
Spec statusW3C Proposal (early)Open standard (stable)Mature standard

🎯 Key Takeaways

  • WebMCP is a W3C proposal co-developed by Google, Microsoft, and W3C — not yet a stable standard.
  • Tools are JavaScript functions registered on your page via navigator.mcp.registerTool().
  • Unlike backend MCP, WebMCP tools run in the live browser page — the user sees changes in real time.
  • The human-in-the-loop model is WebMCP's core advantage over server-side AI integrations.
  • Tool schema quality directly determines how accurately the AI agent selects and calls your tools.

⚠ Common Mistakes to Avoid

    Treating WebMCP like backend MCP — the tools run in the browser, not on a server. There is no separate process.
    Registering tools before the page is fully loaded — always register inside DOMContentLoaded or equivalent.
    Writing vague tool descriptions — the LLM uses the description to decide when to call the tool. Be explicit.
    Ignoring the proposal status — WebMCP is not yet a stable W3C standard. Do not ship to production without a polyfill or feature flag.
    Exposing too many tools at once — start with 3 to 5 focused tools. LLMs perform better with a smaller, well-defined toolset.

Interview Questions on This Topic

  • QWhat is WebMCP and how does it differ from backend MCP?Reveal
    WebMCP is a W3C proposal that lets web pages expose JavaScript functions as AI-callable tools running directly in the browser. Backend MCP runs tools on a separate server process. The key difference: WebMCP tools execute in the live page context, so the user sees UI changes in real time and stays in the loop. Backend MCP requires the agent to provide its own UI separately.
  • QWhy is the human-in-the-loop aspect important in WebMCP?Reveal
    Because WebMCP tools run inside the running page, the user watches the AI agent's actions happen live in their own UI. They can intervene, correct, or approve at any point. This is fundamentally different from backend integrations where the agent acts autonomously and the user only sees the final result.
  • QWhat organisations are behind WebMCP?Reveal
    WebMCP is co-developed by Google, Microsoft, and the W3C Web Machine Learning Working Group. It is an early-stage proposal, not yet a ratified standard.
  • QWhen would you choose WebMCP over backend MCP?Reveal
    Choose WebMCP when the user needs to stay in the loop and see live UI changes, when you want to avoid running a separate server, or when your tools naturally belong in the frontend (DOM manipulation, form filling, UI filtering). Choose backend MCP when the agent needs to interact with databases, internal APIs, or services that should not be exposed to the browser.

Frequently Asked Questions

Can I use WebMCP in production today?

Not in stable browsers — WebMCP is still a W3C proposal. Monitor the Web Machine Learning Working Group at github.com/webmachinelearning/webmcp for ratification updates.

Does WebMCP work with any AI model?

Yes, as long as the browser-integrated agent supports the WebMCP protocol. The tools you register are model-agnostic — the schema-driven approach works with any LLM that can call structured tools.

What is the difference between a WebMCP tool and a regular JavaScript function?

A WebMCP tool is a regular JavaScript function wrapped in a structured schema (name, description, parameters) and registered with the browser agent via navigator.mcp. The schema is what makes the function discoverable and callable by an AI agent.

🔥
Naren Founder & Author

Developer and founder of TheCodeForge. I built this site because I was tired of tutorials that explain what to type without explaining why it works. Every article here is written to make concepts actually click.

← PreviousObservables and RxJSNext →Introduction to Angular: Components, Modules and Services
Forged with 🔥 at TheCodeForge.io — Where Developers Are Forged