@isoloop/webmcp
connectWebMCP
Experimental
Registers every tool kernel.tools() lists with WebMCP's registerTool
(on document.modelContext, or on navigator.modelContext where only
that exists), with its name, title, description, JSON Schemas and hints
(readOnlyHint, consequentialHint, untrustedContentHint, each sent
only when true). A call runs
kernel.request(tool.topic, input, { timeoutMs: tool.timeoutMs, signal, via: 'webmcp' })
and resolves with the reply; a failed call rejects with the kernel's
BusError (its code and message), for example timeout,
no_responder or dropped. Chromium shows the agent its own generic error; Firefox
passes the message on.
- Where neither exists (no WebMCP, or the flag off), it does nothing and returns a function that does nothing.
- Tools stay registered while their isolates restart.
- A call is aborted (
BusError('aborted')) when the browser cancels it: through the call's own signal, or atoolcancelevent, which names only the tool, so it aborts every call of that tool in flight. Where the browser gives neither (Firefox 159), a call runs until its reply or itstimeoutMs. - A tool name it already registered on this page and hasn't unregistered
(a second
connectWebMCPbefore the first disconnects) throwsKernelError('invalid_config')naming the tool, and nothing is registered. Names other scripts registered aren't seen. - The returned function unregisters every tool (it aborts the registration
signal, and calls
unregisterToolwhere that exists) and aborts the calls still in flight.
There is no shim for browsers without WebMCP; during development the dev
MCP (@isoloop/host/dev-mcp) covers them. A tool's hints tell the agent
what it does; asking the user before a consequential call is the agent's
job.
function connectWebMCP(kernel: Pick<Kernel, "tools" | "request">): () => void;
| Parameter | Description |
|---|---|
kernel |
A kernel created with agents.expose (only tools() and request() are used). |
Returns: A function that unregisters the tools.
Throws:
- {KernelError}
invalid_configwhen one of the tools is already registered by an earlierconnectWebMCPon this page.
Example:
import { connectWebMCP } from '@isoloop/webmcp';
const disconnect = connectWebMCP(kernel);
Guides: Tools for agents.