Barjo: A Worked Example of WebMCP
A small Discogs clone in which the page publishes its own tools to an agent, and three rules for the shape those tools should take
WebMCP is a draft standard that lets a web page publish its own tools to an AI agent through document.modelContext. Rather than leaving the agent to guess which pixel is the search box, the page declares what it offers: here is search_collection, here is what it takes, and here is what it returns. Barjo is a Discogs clone built as a worked example of the standard, with forty-five real records, no backend, no loading states, and ten tools an agent can call.
The app runs in any browser, but only Chrome with the enable-webmcp-testing flag provides a native document.modelContext. Elsewhere a polyfill installs a spec-shaped one, so the tools still register and the built-in inspector can run them; there is simply no browser-level agent to call them. A desktop agent such as Claude Code cannot see the tab on its own, so a local relay speaks MCP over stdio on one side and WebSocket to the page on the other. Once the relay is registered, the ten tools appear in the agent’s tool list like those of any other MCP server.
The shape of the tools
The API calls amount to five lines. What the example has to teach lies in the shape of the tools, which are held to three rules.
The first is that tools model user goals, not widgets. There is no click_search_button or set_genre_checkbox, only search_collection, show_release and update_crate. A tool that mirrors a control forces the agent to reverse-engineer the interface before it can be of any help. The test is whether the tool could be explained to someone who has never seen the page.
The second is that tools go through the state layer and never through the DOM. Every handler calls the same store action that a click handler calls, and none of them touches document.querySelector. Two things follow. The screen always reflects what the agent did, because the agent mutates the same state the grid renders from; and a person can take over mid-task, because there is no separate agent state to reconcile.
execute: (input) => {
const release = resolveRelease(input)
useCollection.getState().setRating(release.id, input.rating)
return { id: release.id, rating: /* re-read, don't assume */ }
}
The third is that a tool returns the data needed to decide what to do next. A tool that returns { ok: true } forces the agent to take a screenshot and squint. search_collection returns the matching releases and update_crate the crate’s new contents, which usually lets the turn end in a single call. The counterweight is Chrome’s guidance on character budgets: list results are deliberately thin, and a tracklist arrives only when a single release is asked for.
What matters in the repository is the src/webmcp/ directory. The tools file is the place to start, since the reasoning behind each tool is written beside it; everything else is an ordinary React application whose job is to give the tools something real to drive.