WebMCP
Experimental
This is an experimental package. API shape may drift.
@ag2b/plugin-webmcp bridges every Tool on the agent into the browser's WebMCP API — so the host browser agent can call the same tools your AG2B agent already uses.
Try it
WebMCP isn't on by default anywhere. To exercise the bridge end-to-end:
- Open flag settings in Chrome 148.0.7778.56 or higher (currently the only browser shipping WebMCP), enable WebMCP for testing, and restart.
- Install the Model Context Tool Inspector extension.
- Generate a Gemini API key at Google AI Studio and paste it into the extension's settings — the inspector needs it to invoke your bridged tools.
Installation
npm i @ag2b/plugin-webmcpUsage
Install the plugin once, after scopes are registered:
import { createAgent, OpenAiProvider, Scope, Tool } from '@ag2b/core';
import { webmcp } from '@ag2b/plugin-webmcp';
import { z } from 'zod/v4';
const setBackground = new Tool({
name: 'setBackground',
description: 'Change the page background color.',
parameters: z.object({
color: z.string().describe('Any valid CSS color (name, hex, rgb, etc.)'),
}),
handler: ({ color }) => {
document.body.style.backgroundColor = color;
},
});
const agent = createAgent({ provider: new OpenAiProvider({ baseURL: '/api/llm' }) });
agent.scopes.register(new Scope({ name: 'appearance', tools: [setBackground] }));
void agent.use(webmcp());Every tool registered with the agent — now and in the future — appears under navigator.modelContext. Unregister a Scope and its tools disappear from WebMCP too.
What gets bridged
- Tools — name, description, JSON Schema, and
executeare mapped 1:1. Tool name validation, Zod validation, andenabledchecks all run inside the bridgedexecutecallback, so disabled tools reject with a descriptive error at call time. - Scopes — tracked by lifecycle: tools register on
onScopeRegister, unregister viaAbortController.abort()ononScopeUnregister. - Scope context — not bridged. WebMCP has no primitive for it.