1 Install
<script src="https://cdn.jsdelivr.net/npm/@rckflr/[email protected]/browser-mcp.js"></script>
Or: npm install @rckflr/browser-mcp
2 Register Tools
const mcp = new BrowserMCP({ name: "My Site" }); // Public tool — anyone can call mcp.tool("search", "Search this page", { query: "string" }, ({ query }) => document.body.innerText.includes(query) ? "Found" : "Not found", { public: true } ); // Protected tool — requires auth mcp.tool("edit_page", "Edit page content", { html: "string" }, ({ html }, user) => { document.body.innerHTML = html; return "Updated by " + user.name; }, { roles: ["admin"] } );
3 Add Auth (Optional)
// Simple token-based auth const TOKENS = { "secret-admin-key": { id: "admin", role: "admin", name: "Admin" }, "editor-key": { id: "editor", role: "editor", name: "Editor" }, }; mcp.requireAuth((token) => TOKENS[token] || null); // Or verify against your API mcp.requireAuth(async (token) => { const res = await fetch("/api/verify", { headers: { Authorization: `Bearer ${token}` } }); return res.ok ? await res.json() : null; });
4 Start
mcp.start(); // Widget appears. Agents can connect. That's it.
5 mcpTool() — Universal API
Works in both standalone mode (browser-mcp.js) and MCP Browser (Tauri desktop app).
// Register a tool that works in BOTH runtimes mcpTool("search", "Search products", { query: { type: "string" } }, (args) => products.filter(p => p.name.includes(args.query)) );
In standalone mode, tools sync with BrowserMCP on start(). In MCP Browser, the bridge picks them up automatically. See shop demo →
MCP Browser — Desktop App
A custom Tauri browser with a built-in MCP HTTP server. Any page you visit exposes tools to external AI agents via POST http://localhost:PORT/mcp.
Auto-inject
MCP bridge injected into every page automatically
6 Auto-tools
page_title, page_url, page_text, page_html, query_selector, navigate
Custom tools
Pages register via mcpTool() — same API
Verified
Tested: navigate to shop on CF Pages → 12 tools → search, cart
Connect Your Agent
Two ways to connect an AI agent to a site running browser-mcp:
Option A — MCP Browser (recommended)
Download MCP Browser, open any site, and point your agent to the HTTP server:
# 1. Download and launch MCP Browser # 2. Navigate to any site (e.g. browser-mcp.automators.work/mcp-shop-demo.html) # 3. Connect your agent: # Claude Code claude mcp add mcp-browser --transport http --url http://127.0.0.1:4567/mcp # Claude Desktop (claude_desktop_config.json) { "mcpServers": { "mcp-browser": { "url": "http://127.0.0.1:4567/mcp" } } } # Any agent — just POST curl -X POST http://127.0.0.1:4567/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
Option B — BroadcastChannel (same browser)
For agents running in the same browser, connect via BroadcastChannel:
const channel = new BroadcastChannel("browser-mcp"); channel.postMessage({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }); channel.onmessage = (e) => console.log(e.data);
Features
Tools
Let agents perform actions on your site
Resources
Expose data via URIs (static or template)
Prompts
Pre-built templates for agent interactions
Auth + Roles
Token-based auth with role restrictions
Session Management
Auto-expiring sessions (1h TTL)
Widget
Floating status indicator with tool list
BroadcastChannel
Cross-tab communication for agents
WordPress Plugin
13 tools for WP admin automation
Prompts
Prompts are pre-built templates that agents can discover and use to structure their interactions with your site. Define them once, and any connected agent can list and invoke them.
// Summarize page content with a focus area mcp.prompt("summarize", "Summarize this page", [{ name: "focus", description: "What to focus on" }], ({ focus }) => `Summarize this page, focusing on ${focus}. Content: ${document.body.innerText.slice(0, 3000)}` ); // Generate a code review prompt mcp.prompt("code_review", "Review code on this page", [{ name: "language", description: "Programming language" }], ({ language }) => `Review the ${language} code on this page for bugs, security issues, and improvements.` ); // Translate page content mcp.prompt("translate", "Translate page content", [{ name: "target_lang", description: "Target language" }], ({ target_lang }) => `Translate the following to ${target_lang}: ${document.body.innerText.slice(0, 2000)}` );
Agents discover prompts via prompts/list and invoke them with prompts/get. Arguments are passed as key-value pairs.
Resources
Resources expose data from your site via URIs that agents can read. They can be static (fixed URI) or dynamic (URI templates with parameters).
// Static resource — fixed URI mcp.resource("page://title", "Page title", "text/plain", () => document.title ); mcp.resource("page://content", "Full page text", "text/plain", () => document.body.innerText.slice(0, 5000) ); // Dynamic resource — URI template with parameter mcp.resource("page://meta/{name}", "Get meta tag value", "text/plain", ({ name }) => { const meta = document.querySelector(`meta[name="${name}"]`); return meta ? meta.content : "Not found"; } ); // JSON resource mcp.resource("page://links", "All links on this page", "application/json", () => JSON.stringify([...document.querySelectorAll('a[href]')].map(a => ({ text: a.textContent.trim(), href: a.href }))) );
Agents discover resources via resources/list and read them with resources/read. URI templates (with {param}) appear in resources/templates/list.
Sampling
Sampling lets your tools request LLM completions through the connected agent. The user sees a modal to approve or edit the response (human-in-the-loop).
// Enable sampling (shows approval modal by default) mcp.enableSampling(); // Use sampling inside a tool handler mcp.tool("ask_ai", "Ask AI a question about this page", { question: "string" }, async ({ question }) => { const result = await mcp.createSamplingMessage({ messages: [{ role: "user", content: { type: "text", text: question } }], systemPrompt: "You are a helpful assistant. Use the page context to answer.", maxTokens: 200 }); return result.content.text; }, { public: true } );
Flow:
Agent calls tool → tool calls createSamplingMessage() → modal appears in browser → user types/approves response → result returned to tool → tool returns to agent
You can also provide a custom handler to enableSampling(fn) to skip the modal and handle sampling programmatically.
API Reference
Constructor
new BrowserMCP({ name, version, description, widget, endpoint })
Registration
mcp.tool(name, desc, schema, handler, opts?) | Register a tool. opts: { public, roles } |
mcp.resource(uri, desc, mime?, handler) | Expose data. URI templates: "data://{id}" |
mcp.prompt(name, desc, args, handler) | Prompt template |
mcp.requireAuth(verifier) | (token) => user | null |
mcp.enableSampling(handler?) | Enable sampling. Optional custom handler, default shows modal. |
mcp.createSamplingMessage(params) | Request completion from user/LLM. Callable from tool handlers. |
Lifecycle
await mcp.start() | Start server, show widget |
mcp.stop() | Stop server, remove widget |
mcp.listTools() | Get tool names array |
Direct Access
mcp.handleRequest(jsonRpc) | Call MCP method directly (for testing) |
window._browserMCP | Global reference after start() |
Auth Flow (for agents)
| 1. | Call auth_login with token → get session ID |
| 2. | Include _auth_token in all tool calls |
| 3. | Sessions expire after 1 hour |
Live Playground
This page is running a BrowserMCP server right now. Try calling tools:
WordPress Plugin
Drop the plugin into wp-content/plugins/browser-mcp/ and activate. 13 tools auto-registered:
| Tool | Roles | Action |
|---|---|---|
wp_site_info | public | Site metadata |
wp_search | public | Search posts/pages |
wp_list_posts | auth | List posts |
wp_create_post | editor+ | Create post |
wp_update_post | editor+ | Edit post |
wp_delete_post | editor+ | Delete post |
wp_list_users | admin | List users |
wp_get_settings | admin | WP settings |
wp_list_plugins | admin | Installed plugins |
Use Cases
E-commerce
Agents search products, check inventory, add to cart
CMS / WordPress
Create posts, manage content, moderate comments
Dashboards
Expose metrics and KPIs to AI analysis
Documentation
Make docs searchable and navigable by agents
Internal Tools
AI-automate any web app your team uses
Prototyping
Quickly expose any page for agent testing