browser-mcp

Turn any webpage into an MCP server. Zero dependencies. One script tag.

8 KB MCP Spec Compliant Auth + Roles Zero Deps
npm  |  GitHub  |  Try It Live  |  WordPress Plugin
MCP server starting...

1 Install

<script src="https://cdn.jsdelivr.net/npm/@rckflr/browser-mcp@0.3.0/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.

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

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._browserMCPGlobal 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:

Click a button to see results...

WordPress Plugin

Drop the plugin into wp-content/plugins/browser-mcp/ and activate. 13 tools auto-registered:

ToolRolesAction
wp_site_infopublicSite metadata
wp_searchpublicSearch posts/pages
wp_list_postsauthList posts
wp_create_posteditor+Create post
wp_update_posteditor+Edit post
wp_delete_posteditor+Delete post
wp_list_usersadminList users
wp_get_settingsadminWP settings
wp_list_pluginsadminInstalled plugins

View plugin source on GitHub

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