---
## The Web Standard
The [Web Model Context API](https://webmachinelearning.github.io/webmcp/) is a [W3C Community Group](https://www.w3.org/community/webmachinelearning/) draft spec. It makes every browser tab a **tool source** — web pages register tools that AI agents can discover and call:
```
document.modelContext
├── .registerTool(tool, { signal }) Register a tool for AI agents
├── .getTools() Discover registered tools
└── .executeTool(tool, inputObject) Execute a discovered tool
```
The Community Group publishes the official [`@w3c/webmcp-polyfill`](https://github.com/w3c-oss/webmcp-polyfill) for browsers without native support and [`webmcp-types`](https://www.npmjs.com/package/webmcp-types) for TypeScript. MCP-b **bridges** that API to the full [Model Context Protocol](https://modelcontextprotocol.io/) — turning that tool source into a complete MCP server with prompts, resources, and browser transports.
> Built by [MCP-b](https://docs.mcp-b.ai). Not an official W3C or MCP project.
## Getting Started
### 1. Use the web standard directly
If you're running Chrome 155 or later with WebMCP enabled (see [Chrome's WebMCP overview](https://developer.chrome.com/docs/ai/webmcp) for the origin trial and the local testing flag), `document.modelContext` is already there. Just use it:
Use the official [`webmcp-types`](https://www.npmjs.com/package/webmcp-types) for core browser
contracts and input schema inference. MCP-B adapter extensions and schema helpers live in
`@mcp-b/webmcp-ts-sdk`.
```ts
if (!document.modelContext) throw new Error('WebMCP is unavailable');
await document.modelContext.registerTool({
name: 'add_todo',
description: 'Add a new todo item',
inputSchema: {
type: 'object',
properties: { title: { type: 'string' }, done: { type: 'boolean' } },
required: ['title'],
} as const, // ← args inferred: { title: string; done?: boolean }
execute: async (args) => ({ id: Date.now(), title: args.title }),
});
```
### 2. Polyfill it
Want it to work without native support, including in Firefox and Safari? Add the official W3C polyfill — same API, same code:
```ts
import '@w3c/webmcp-polyfill/auto'; // pnpm add @w3c/webmcp-polyfill; keeps native support when present
if (!document.modelContext) throw new Error('WebMCP is unavailable');
await document.modelContext.registerTool({
name: 'get_page_title',
description: 'Returns the current page title',
inputSchema: { type: 'object', properties: {} },
execute: async () => ({
content: [{ type: 'text', text: document.title }],
}),
});
```
The official polyfill covers the imperative API. For declarative tools in browsers without native support, use `@mcp-b/global` or `@mcp-b/webmcp-polyfill` for now.
Or with React: `pnpm add usewebmcp`
```tsx
'use client';
import { useWebMCP } from 'usewebmcp';
function PageTitle() {
useWebMCP({
name: 'get_page_title',
description: 'Returns the current page title',
execute: async () => ({ title: document.title }),
});
// ...
}
```
### 3. Full MCP server
Need the full [Model Context Protocol](https://modelcontextprotocol.io/) — prompts, resources, transports, and interop with Claude Desktop, Cursor, or another MCP client? Use `@mcp-b/global`:
```ts
import '@mcp-b/global'; // pnpm add @mcp-b/global
if (!document.modelContext) throw new Error('WebMCP is unavailable');
// Same registerTool API — now backed by a full MCP server
await document.modelContext.registerTool({
name: 'add_todo',
description: 'Add a new todo item',
inputSchema: {
type: 'object',
properties: {
title: { type: 'string', description: 'Todo title' },
},
required: ['title'],
},
execute: async (args) => {
const todo = { id: Date.now(), ...args };
return { content: [{ type: 'text', text: JSON.stringify(todo) }] };
},
});
```
Or as a script tag (zero build step):
```html
```
Or with React: `pnpm add @mcp-b/global @mcp-b/react-webmcp`
```tsx
'use client';
import '@mcp-b/global';
import { useWebMCP } from '@mcp-b/react-webmcp';
function TodoApp({ todos, addTodo }) {
useWebMCP({
name: 'add_todo',
description: 'Add a new todo item',
inputSchema: {
type: 'object',
properties: {
title: { type: 'string', description: 'Todo title' },
},
required: ['title'],
} as const,
execute: async ({ title }) => {
addTodo(title);
return { success: true };
},
});
return (