WebMCP Registers Tools Inside the Page. My MCP Server Keeps Its Secrets Outside It.
I run an MCP server (server.py in this repo) that exposes eight tools over stdio: things like get_repo_stats, list_articles, generate_commit_message. It's the kind of MCP server most people building agent tooling have wr
I run an MCP server (server.py in this repo) that exposes eight tools over stdio: things like get_repo_stats, list_articles, generate_commit_message. It's the kind of MCP server most people building agent tooling have written one version of by now β a Python process, a FastMCP() instance, a pile of @mcp.tool() decorators, credentials pulled from os.environ at call time.
This week WebMCP showed up near the top of my trending feed again β Chrome's May 2026 "Intent to Experiment," a W3C Web Machine Learning Community Group draft, a TAG design review arguing about whether the registration object belongs on navigator or document. The pitch is simple: instead of a separate server process exposing tools over a protocol, the page itself registers tools an in-browser agent can call, via something like:
navigator.modelContext.registerTool({
name: "get_repo_stats",
description: "...",
inputSchema: { /* ... */ },
async execute(input) { /* ... */ }
});
That's close enough to my own tool shape that I wanted to actually port one and run it, rather than just read about it. The spec is still unstable β I found at least three different API shapes across the draft's history (a provideContext({tools}) call, a bare registerTool method, an empty interface placeholder), so take the exact method names below as "current as of this draft," not settled.
Porting a real tool
Here's the actual tool as it exists in server.py:
@mcp.tool()
def get_repo_stats(repo: str) -> dict:
"""Get stars, forks, watchers, open issues for enjoykumawat/<repo>."""
r = _gh(f"/repos/{GITHUB_USERNAME}/{repo}")
return {
"name": r["name"],
"stars": r["stargazers_count"],
"forks": r["forks_count"],
"watchers": r["watchers_count"],
"open_issues": r["open_issues_count"],
"language": r.get("language"),
"description": r.get("description"),
}
_gh() is the function that actually hits api.github.com β it reaches into os.environ.get("GITHUB_TOKEN"), raises if it's missing, and refuses anything but a GET (a deliberate guard, logged in this repo's bugs.md after an earlier version only checked the HTTP verb and let a stray payload through on a GET call).
No browser ships navigator.modelContext yet, so I can't test against a real implementation. What I can do is write the minimal stand-in the spec describes and run the registration + invocation for real, in an actual headless browser, instead of describing it in the abstract:
<script>
window.__registeredTools = [];
navigator.modelContext = {
registerTool(tool) {
window.__registeredTools.push(tool.name);
window.__lastTool = tool;
return { unregister() {} };
}
};
navigator.modelContext.registerTool({
name: "get_repo_stats",
description: "Get stars, forks, watchers, open issues for enjoykumawat/<repo>.",
inputSchema: { type: "object", properties: { repo: { type: "string" } }, required: ["repo"] },
async execute({ repo }) {
return { repo, note: "ran inside the page's own JS context" };
}
});
window.__probe = {
hasProcess: typeof process !== "undefined",
hasProcessEnv: typeof process !== "undefined" && typeof process.env !== "undefined",
};
</script>
Loaded and driven with Playwright:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('file://' + __dirname + '/page.html');
const tools = await page.evaluate(() => window.__registeredTools);
const probe = await page.evaluate(() => window.__probe);
const result = await page.evaluate(async () => {
return await window.__lastTool.execute({ repo: "my-git-manager" });
});
console.log(JSON.stringify({ tools, probe, result }, null, 2));
await browser.close();
})();
The real output:
{
"tools": ["get_repo_stats"],
"probe": { "hasProcess": false, "hasProcessEnv": false },
"result": { "repo": "my-git-manager", "note": "ran inside the page's own JS context" }
}
The tool definition itself ports almost one-to-one: name, description, an input schema, a function. If you squint, @mcp.tool() plus a docstring and registerTool({name, description, inputSchema, execute}) are the same idea wearing two different languages' clothes. That part of the trending take β "WebMCP tool definitions aren't conceptually new" β holds up.
Where the port actually breaks
hasProcess and hasProcessEnv came back false. That's not a bug in my stub, it's just what a browser page is: there's no process.env, no filesystem, no os.environ.get("GITHUB_TOKEN") to reach for. My real get_repo_stats only works because _gh() can read a token that lives server-side, in a process the calling agent never has direct access to β the agent sends a repo name over stdio and gets JSON back; it never sees GITHUB_TOKEN itself.
A WebMCP version of the same tool has nowhere equivalent to put that token. The options are all worse than what I have now:
- Ship the token to the page (in a script tag, a cookie,
localStorage) β now it's readable by any other script on that page, any browser extension with page access, and anyone who opens devtools. - Proxy the actual GitHub call through a backend endpoint the page fetches from β at which point the "tool" running in the page is just a thin wrapper around an API call, and the real tool (the one holding the credential) is back to being a server process, which is where I started.
- Scope the token down to something safe to expose client-side β GitHub doesn't offer a "read public repo stats only" token scope narrow enough to hand to arbitrary page JS; the closest real option is an unauthenticated call to the public API, which exists but is rate-limited far more aggressively than an authenticated one.
None of that is a knock on WebMCP β a page-scoped tool registry makes complete sense for tools that only need what the page already has: reading the DOM, filling a form, clicking a button the user is already looking at. get_repo_stats just isn't that kind of tool. It needs a secret that has no business being anywhere a page's own JavaScript can read it, and that's a property of where the tool runs, not of how its schema is written.
The actual dividing line
Reading through all three WebMCP draft shapes, the thing that doesn't change across any of them is the trust boundary: the tool executes inside the page's JS realm, which means it inherits exactly the page's own privileges β nothing more, nothing less. My MCP server's tools execute inside a process the calling agent connects to but never reads the memory of. That's the actual criterion for picking one shape over the other, and it has nothing to do with how convenient either registration API is to write:
- Does the tool only need what's already on the page (DOM state, something the user typed, something already rendered)? WebMCP's shape fits β no separate process, no separate deployment, the tool ships with the page.
- Does the tool need a credential, a write scope, or anything the page itself shouldn't be able to read? It has to run somewhere the calling agent can reach but the page's own script can't β which today still means a server process, MCP-over-stdio or otherwise.
I went in expecting to write about registration syntax. The actual finding was narrower and more useful, and less flattering to my own server than I expected: zero of my eight tools would port cleanly to WebMCP today. I checked all eight, not just get_repo_stats. The three GitHub tools (get_github_profile, list_repos, get_repo_stats) all go through _gh(), which reads GITHUB_TOKEN unconditionally and raises if it's missing β even though GitHub's REST API allows some of these reads unauthenticated, this server never does. The four DEV.to tools go through _dev(), which does the same with DEV_TO_API. The last one, generate_commit_message, doesn't touch either API key, but it shells out to subprocess.check_output(["claude", "-p", ...]), which only works because it's running on a machine with an active claude CLI OAuth session β not something a browser page can spawn either.
So the dividing line isn't "read-only tools port, write tools don't." It's that every tool in this particular server was written assuming it runs in a process with its own ambient credentials, and I never had to think about that assumption until I tried moving one into a context that doesn't have any.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.