@archon-research/webmcp
v0.7.0
Published
A stable React wrapper over [WebMCP](https://github.com/webmcp-org) (`@mcp-b/global`) for registering UI tools that a connected agent harness can call. It exposes a fixed interface so the fast-moving `@mcp-b/*` packages can churn behind a single seam.
Readme
@archon-research/webmcp
A stable React wrapper over WebMCP (@mcp-b/global) for registering UI tools that a connected agent harness can call. It exposes a fixed interface so the fast-moving @mcp-b/* packages can churn behind a single seam.
Tools are registered into document.modelContext. A tool registered here runs in the consumer's own authenticated browser session, so it reuses the app's existing auth and APIs rather than requiring separate server credentials.
Installation
npm install @archon-research/webmcp reactreact is a peer dependency (>= 19).
Features
- Schema-first tool definitions (
defineTool) - StrictMode-safe registration that mounts/unmounts cleanly
- A React provider that initializes the WebMCP polyfill and a tool registry
- Hooks to register tools, observe the registry, and contribute view state
- Wire-protocol types shared with the relay back-channel
Usage
Wrap your app
import { WebMCPProvider } from '@archon-research/webmcp';
export function App() {
return (
<WebMCPProvider>
<YourApp />
</WebMCPProvider>
);
}Define and register a tool
The handler lives on the spec. Build the spec inside the component (or with a
ref) when it needs to close over component state — useRegisterTool reads the
latest spec through a ref, so it re-registers only when the tool name changes,
never on every render.
import { defineTool, useRegisterTool } from '@archon-research/webmcp';
function IdentityView({ onSelect }: { onSelect: (id: string) => void }) {
const selectIdentityTool = defineTool<{ identityId: string }, { selected: string }>({
name: 'explorer.selectIdentity',
description: 'Select and focus an identity node in the Explorer.',
schema: {
type: 'object',
properties: { identityId: { type: 'string' } },
required: ['identityId'],
},
handler: async ({ identityId }) => {
onSelect(identityId);
return { selected: identityId };
},
});
useRegisterTool(selectIdentityTool);
return null;
}Public surface
defineTool— schema-first tool factoryWebMCPProvider— provider that initializes the polyfill and registryuseRegisterTool— register a tool while a component is mounteduseTool— observe a single tool's spec by nameuseToolRegistry/useToolRegistryRef— read the full registryuseContributeViewState— contribute a partial view-state slicelistTools/getViewState— imperative helpers for non-React callersuseRelayActivity—console.infologger fortool_activityframes- Tool types (
ToolSpec,ToolHandler,ViewState, ...) and the wire-protocol types shared with the relay (@archon-research/mcp-connectand the Python relay)
Related
@archon-research/mcp-connect— the connection UI (chat icon, status indicator, connect modal) that pairs the browser with a harness over the relay.
