SuperAPIAI Directory

browser-ref-mcp

github.com · AI developer platforms

browser-ref-mcp is a browser-control MCP server for AI agents. Its core feature is clicking page elements by reference number (ref) instead of relying on fragile CSS selectors, and it supports session self-healing. It drives the locally installed Chrome or Edge via playwright-core, with no additional browser download required. The server provides semantic snapshots that label page interactive elements as [eN] and flatten cross-origin iframe content into the same tree; when clicking, it locates elements through progressive fallback in the order of CSS path, exact role-plus-name match, fuzzy match, and text match. A health check is performed before every tool call, and after the browser is closed or crashes, the next call automatically restarts it and restores tabs. It supports stdio MCP clients such as Claude Code, Claude Desktop, Cursor, Cline, Codex CLI, Windsurf, and others, and offers two run modes, launch and connect, along with multiple command-line parameters.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

browser-ref-mcp is a browser-control MCP server for AI agents, primarily solving two common problems when agents drive browsing: fragile selectors causing click failures, and sessions being unable to recover after the browser process is interrupted.

Purpose and positioning The server lets agents operate page elements by reference number instead of guessing CSS selectors. It does not download a separate browser; instead, it drives the user's existing local Chrome or Edge via playwright-core. It is suitable for clients that support stdio MCP, including Claude Code, Claude Desktop, Cursor, Cline, Codex CLI, Windsurf, OpenClaw, and others.

Main capabilities

  1. Semantic snapshots: it traverses the DOM within the page, combines accessibility roles, accessible names, and the cursor: pointer heuristic to identify interactive elements, and labels each element as [eN]. Snapshots can penetrate open shadow DOM and flatten cross-origin iframe content into the same tree with unified numbering.
  2. Click by reference: the agent can click the corresponding element by calling browser_click({ "ref": "e42" }). Each reference simultaneously stores a CSS path (anchored on id and combined with nth-of-type, unique within its owning frame) and a semantic description of role plus name. When locating, it falls back progressively in the order of cssPath, getByRole exact match, getByRole fuzzy match, and getByText, and verifies after a hit. If a reference has indeed become invalid, the error message prompts the agent to take a new snapshot or wait first, avoiding retry loops.
  3. Session self-healing: the MCP server itself runs as a persistent daemon, and the browser is launched through a CDP pipe rather than a websocket port, so there are no port conflicts. A browser.isConnected() health check is performed before every tool call; if the browser is manually closed or crashes, the next call automatically restarts it and restores all tabs, while clearly informing the agent that old references are invalid. If a leftover process occupies the profile, it cleans up by profile path and retries. All Playwright calls are wrapped in withTimeout, returning a timeout instead of hanging indefinitely when the browser is stuck.
  4. Logging: full-chain logs are written to ~/.browser-mcp/logs/server-YYYYMMDD.log, rotated at 2 MB, keeping 3 files. browser_get_info shows recent errors and restart count.

Usage Installation can be done with a one-line command that installs the server and a companion brief skill description. You can also add the client configuration manually: point command to node and args to the absolute path of dist/index.js; GUI applications usually do not inherit the shell working directory, so relative paths tend to fail. After configuring, fully restart the client (on macOS, quit from the menu bar; merely closing the window will not reload the configuration). Configuration file locations: for Claude Desktop, on macOS ~/Library/Application Support/Claude/claude_desktop_config.json, on Windows %APPDATA%\Claude\claude_desktop_config.json; for Cursor, ~/.cursor/mcp.json or Settings → Features → MCP; for Claude Code, use claude mcp add or the same mcpServers structure.

Run modes

  • launch mode (default): starts a dedicated Chrome with its profile at ~/.browser-mcp/profile; login state persists across restarts, so each site only needs to be logged in once in that profile.
  • connect mode: connects to a running browser with the debugging port enabled; that browser is not closed on exit.

Configuration precedence is: command-line arguments > environment variables (BROWSER_MCP_*) > ~/.browser-mcp/config.json > built-in defaults. Common arguments include --headless, --profile <dir>, --channels chrome,msedge, --executable <path>, --viewport 1440x900, --start-url <url>, --dialogs accept|dismiss (default accept), appended after the package name. The full list can be viewed with npx -y browser-ref-mcp --help.

Use cases Suitable for automation tasks that require an agent to operate web pages reliably, such as form filling, page navigation, cross-iframe interaction, and long-session browsing that needs to maintain login state.

Limitations and notes

  • Do not set executablePath unless necessary; once set, the chrome → msedge channel fallback chain is skipped, leaving only a single candidate and reducing robustness across machines.
  • The dedicated profile stores live login cookies and constitutes browser identity information; never commit it to any repository.
  • Page dialogs are auto-accepted by default. The agent cannot handle CAPTCHA or payment flows; these still require human intervention.
  • Logs may contain page URLs with query parameters and should be cleaned up after debugging.
  • File upload, richer download management, request interception, cookie/storage management, PDF export, and a CLI frontend are listed as future directions; the current materials do not state that they are already provided.
  • Fees, pricing, and the specific range of supported platforms are not yet provided.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools