{
  "markdown": "<!-- mcp-name: io.github.paipaipai666/nexus-browser-mcp -->\n\nEnglish | [简体中文](README.zh-CN.md)\n\n# nexus-browser-mcp\n\n[![PyPI](https://img.shields.io/pypi/v/nexus-browser-mcp)](https://pypi.org/project/nexus-browser-mcp/)\n[![CI](https://github.com/paipaipai666/nexus-browser-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/paipaipai666/nexus-browser-mcp/actions/workflows/ci.yml)\n[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)\n[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)\n[![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.paipaipai666%2Fnexus--browser--mcp-purple)](https://registry.modelcontextprotocol.io/v0.1/servers?search=nexus-browser-mcp)\n[![Glama](https://glama.ai/mcp/servers/paipaipai666/nexus-browser-mcp/badges/score.svg)](https://glama.ai/mcp/servers/paipaipai666/nexus-browser-mcp)\n\n**A browser-automation MCP server with event-driven, deterministic snapshots.**\n\nBuilt on Playwright. Drives a browser for LLMs through the Accessibility Tree — navigate, click, type, read, fill forms, manage tabs. Key differences from alternatives (e.g. Playwright MCP):\n\n1. **Deterministic snapshots**: no fixed-interval `sleep` guessing. A `MutationObserver` records the last DOM mutation and the browser's own `requestAnimationFrame` loop decides when the page has been quiet for `STABLE_WINDOW_MS` (default 800ms) before extracting a snapshot — eliminating \"captured mid-animation\" races.\n2. **Built-in governance gates**: HITL rules (e.g. clicking \"pay/confirm\" requires human approval), `browser_evaluate` disabled by default with unconditional confirmation, JSONL audit log (sensitive-parameter redaction + per-call in/out character metering, so token cost can be reconciled).\n3. **Multi-task isolation**: one MCP connection (session) can host multiple independent `task_id`s, each with its own BrowserContext (no login-state cross-contamination). Idle tasks are reclaimed by TTL; on next use they're rebuilt and the last page is restored automatically.\n4. **Death observability + self-healing**: if a tab or the whole browser is closed externally or crashes, the next call rebuilds it automatically (a persistent profile keeps your login state) and prepends a `[state change]` notice telling the agent exactly what was restored and what was lost — no raw Playwright exceptions leak through.\n5. **Developer observability**: every page records console messages, uncaught JS exceptions and network request metadata (method/URL/status/failure reason — **never bodies**) into capped ring buffers; `browser_console` / `browser_errors` / `browser_network` read them incrementally via a `since` cursor, so the agent can answer \"why did nothing happen\" instead of guessing.\n\n## Installation\n\n```bash\npip install nexus-browser-mcp\n# or\nuvx nexus-browser-mcp\n```\n\nTwo executable entry points are installed: `nexus-browser-mcp` and `nexus-browser`. A guaranteed fallback: `python -m nexus_browser.server`.\n\nRequires `playwright` and its browser binary:\n\n```bash\npip install playwright && playwright install chromium\n```\n\n## Integrate (any MCP client)\n\n**opencode** (`~/.config/opencode/opencode.json`):\n\n```json\n{\n  \"mcp\": {\n    \"browser\": {\n      \"type\": \"local\",\n      \"command\": [\"uvx\", \"nexus-browser-mcp\"],\n      \"enabled\": true\n    }\n  }\n}\n```\n\n**Claude Code** (`.mcp.json`, project root):\n\n```json\n{\n  \"mcpServers\": {\n    \"browser\": {\n      \"type\": \"stdio\",\n      \"command\": \"uvx\",\n      \"args\": [\"nexus-browser-mcp\"]\n    }\n  }\n}\n```\n\n**Pi Coding Agent**: reads standard MCP configuration — project `.mcp.json` or user-global `~/.config/mcp/mcp.json`; stdio is the default transport:\n\n```json\n{\n  \"mcpServers\": {\n    \"browser\": {\n      \"command\": \"uvx\",\n      \"args\": [\"nexus-browser-mcp\"]\n    }\n  }\n}\n```\n\nSee `docs/INTEGRATE.md` for details (Chinese).\n\n## Use your own browser (with login state)\n\nBy default, `isolated` mode launches Playwright's bundled Chromium **without your cookies/login state**. To use your own browser, pick one:\n\n**Option A — load your browser profile directly (recommended, simplest)**\n\nUse system Chrome with your everyday user data directory (cookies/login/bookmarks included):\n\n```\nBROWSER_CHANNEL=chrome\nBROWSER_USER_DATA_DIR=\"C:\\Users\\<you>\\AppData\\Local\\Google\\Chrome\\User Data\"\n```\n\n> Note: while running against your real User Data, the process owns the browser — launching your own Chrome concurrently will conflict. Prefer a copied profile or a dedicated `--user-data-dir`.\n\n**Recommended: a tool-dedicated profile (no conflict with your daily browser)**\n\nUse `BROWSER_CHANNEL=chrome` plus a dedicated user data dir (e.g. `C:\\Users\\<you>\\.nexus-browser\\chrome-profile`):\n\n```\nBROWSER_CHANNEL=chrome\nBROWSER_USER_DATA_DIR=\"C:\\Users\\<you>\\.nexus-browser\\chrome-profile\"\n```\n\nOn first use, log in to target sites once in the dedicated Chrome window that pops up when the agent calls a browser tool. Cookies persist in that profile forever after — the agent carries login state while staying fully isolated from your daily browser.\n\n**Option B — attach to a running Chrome via CDP**\n\nStart `chrome --remote-debugging-port=9222` first, then set `BROWSER_MODE=cdp`.\n\n> If the CDP connection fails, the server now **fails loudly** (no silent fallback to a fresh browser) and tells you to start the debug-port browser first.\n\nIn CDP (or persistent-profile) mode the agent can also **take over tabs you already have open**: `browser_list_pages` shows them under \"external tabs\", and `browser_adopt_page(ext_index)` pulls one into the task (snapshot/click/read all work from then on). Adoption always requires `confirmed=true` — it hands the agent full read/write access to that page, including its login state.\n\n## Configuration (environment variables)\n\nEvery option can be overridden via `BROWSER_`-prefixed env vars:\n\n> **评测/全功能使用**：两个高危能力默认关闭（安全优先）。需要 `browser_evaluate` 时设 `BROWSER_ALLOW_JS_EXECUTION=true`，需要 `browser_network_body` 时设 `BROWSER_ALLOW_NETWORK_BODY=true`——冷启动跑基准/评测不开它们，对应子任务会被拒（这是设计，不是故障）。\n\n| Variable | Default | Description |\n|---|---|---|\n| `BROWSER_MODE` | `isolated` | `isolated` (fresh isolated browser) / `cdp` (attach to your Chrome) |\n| `BROWSER_CDP_ENDPOINT` | `http://localhost:9222` | CDP endpoint |\n| `BROWSER_CHANNEL` | `\"\"` | System browser channel: `chrome`/`msedge` etc. (empty = Playwright bundled Chromium) |\n| `BROWSER_USER_DATA_DIR` | `\"\"` | User data dir (carries cookies/login). When set, one shared persistent context across tasks. Empty = fresh profile |\n| `BROWSER_HEADLESS` | `false` | Headless mode (isolated only) |\n| `BROWSER_DEFAULT_TIMEOUT_MS` | `30000` | Playwright per-operation timeout (navigation etc.) |\n| `BROWSER_TOOL_TIMEOUT_MS` | `60000` | Outer timeout guard per tool call (returns ERROR instead of hanging) |\n| `BROWSER_STABLE_WINDOW_MS` | `800` | Quiet window: how long without DOM mutations counts as \"stable\" |\n| `BROWSER_STABLE_REQUIRED` | `2` | Fallback only: consecutive identical snapshots confirming stability, used when the MutationObserver watcher is unavailable (primary path verifies \"zero mutations during capture\" via the mutation timeline directly) |\n| `BROWSER_STABLE_TIMEOUT_MS` | `3000` | Total stability-wait timeout; degrades gracefully on expiry |\n| `BROWSER_SNAPSHOT_MAX_NODES` | `100` | Max nodes per snapshot |\n| `BROWSER_CONTEXT_TTL_SEC` | `600` | Idle task auto-reclaim (seconds) |\n| `BROWSER_STREAM_CHAR_CAP` | `16000` | Max chars per stream buffer (oldest dropped with a seam marker) |\n| `BROWSER_STREAM_PAGE_CAP` | `64000` | Total stream buffer chars per page |\n| `BROWSER_EVENT_MAX_ENTRIES` | `500` | Max events (console/exception/request) per page, oldest dropped with a counter |\n| `BROWSER_EVENT_TEXT_CAP` | `500` | Per-event text truncation length |\n| `BROWSER_EVENT_HANDLE_MAX` | `50` | Recent requests per page keeping a live response handle (for on-demand body reads) |\n| `BROWSER_ALLOW_NETWORK_BODY` | `false` | Allow `browser_network_body` (response bodies may carry sensitive data) |\n| `BROWSER_NETWORK_BODY_CAP` | `4000` | Max chars returned per response body |\n| `BROWSER_TRANSPORT` | `stdio` | `stdio` / `http` (streamable-http for remote/multi-client) |\n| `BROWSER_HTTP_HOST` | `127.0.0.1` | HTTP bind address; non-localhost requires `BROWSER_HTTP_TOKEN` (refuses to start otherwise) |\n| `BROWSER_HTTP_PORT` | `8817` | HTTP port |\n| `BROWSER_HTTP_TOKEN` | `\"\"` | Bearer token for HTTP transport |\n| `BROWSER_ALLOW_JS_EXECUTION` | `false` | Allow `browser_evaluate` (unconditional HITL when enabled) |\n| `BROWSER_HITL_RULES` | `[]` | JSON array of HITL rules, e.g. `[{\"action\":\"click\",\"name_pattern\":\"pay|confirm\"}]` |\n| `BROWSER_AUDIT_PATH` | `~/.nexus-browser/audit.jsonl` | Audit log path |\n| `BROWSER_DIALOG_TIMEOUT_MS` | `20000` | Parked confirm/prompt auto-dismiss timeout (trail kept in event log) |\n| `BROWSER_DOWNLOAD_DIR` | `~/.nexus-browser/downloads` | Where accepted downloads are saved (click reports filename + path) |\n| `BROWSER_PROXY` | `\"\"` | `none` = launch browser with `--no-proxy-server` (bypass system proxy) |\n\n## Tools\n\n34 tools: `browser_navigate`, `browser_navigate_back`, `browser_snapshot`, `browser_click`, `browser_type`, `browser_hover`, `browser_press_key`, `browser_select_option`, `browser_upload_file` (HITL-confirmed), `browser_drag`, `browser_dialog_respond` (dialogs are parked for agent/user decision; accept requires `confirmed=true`), `browser_adopt_page` (take over an already-open browser tab in cdp/persistent mode; HITL-confirmed), `browser_read`, `browser_screenshot`, `browser_evaluate`, `browser_wait`, `browser_wait_stable`, `browser_wait_ms`, `browser_scroll`, `browser_scroll_to`, `browser_wait_navigation`, `browser_find` (locate content by text → refs), `browser_dismiss_popup`, `browser_list_pages`, `browser_switch_page`, observability tools `browser_console`, `browser_errors`, `browser_network`, `browser_perf`, `browser_network_body`, plus 4 lifecycle tools: `browser_tasks`, `browser_close_task`, `browser_list_sessions`, `browser_close_session`.\n\nObservability (debugging): console output, uncaught exceptions and request metadata are buffered per page from creation; `browser_errors()` returns a merged \"JS exceptions + console.error + failed requests\" view in one call. All three support a `since` cursor (omit = continue from last read, `0` = full) and `limit` paging.\n\nPerformance: `browser_perf()` returns FCP/LCP/CLS/INP, navigation timings and the 5 slowest resources. Response bodies can be fetched on demand with `browser_network_body(seq)` — off by default (`BROWSER_ALLOW_NETWORK_BODY`), every call gated by `confirmed=true`, hard char cap, and the body never enters the audit log.\n\n## Token cost: measured, not claimed\n\nSame 10-step task, both servers at default config, metered at the JSON-RPC payload layer (cl100k tokens; harness + raw data in [docs/bench/token-comparison.md](docs/bench/token-comparison.md), reproduce with `bench/compare.py`):\n\n| | nexus-browser-mcp | playwright-mcp |\n|---|---:|---:|\n| 10-step task total | **3,460 tok** | 26,032 tok |\n| snapshot right after navigate | **65 tok** | 6,931 tok |\n\n**7.5x fewer tokens overall; 100x on repeated snapshots** — the dominant cost in real agent loops (polling, multi-step forms, state confirmation).\n\nReal-site benchmark (7 scenarios × 5-7 verifiable sub-tasks each: Baidu/Bing/DuckDuckGo search, Wikipedia reading, Hacker News, GitHub browsing — [docs/bench/realworld.md](docs/bench/realworld.md)): **sub-task completion 37/42 vs 31/42**, **18.2k vs 566.4k tokens (31x)**, wall-clock **107s vs 179s** — one Wikipedia article snapshot alone costs pw-mcp ~252k tokens where nexus caps + diffs. Enterprise task suite (filter/sort, dashboard reading, KB answers, multi-step ordering, price comparison — [docs/bench/enterprise-ops.md](docs/bench/enterprise-ops.md)): **21/21 on all three servers (vs playwright-mcp and chrome-devtools-mcp); tokens 3.6k vs 5.1k vs 10.9k**. At scale (**106 cases / 184 sub-tasks, three servers, seeded deterministic fixtures** — [docs/bench/scale-ops.md](docs/bench/scale-ops.md)): **completion 184/184 vs 180/184 vs 178/184; tokens 153.5k vs 180.5k vs 231.1k (1.00 : 1.18 : 1.51)** — the competitor gaps are stable zeros (richtext-iframe writes, download observability, right-click), not noise.\n\nElement-identification accuracy on adversarially complex pages (duplicate-name button grids, shadow DOM, iframes, hidden/disabled traps, full re-render — [docs/bench/element-acc.md](docs/bench/element-acc.md)): **nexus 92% = pw 92% < chrome-devtools-mcp 100%, with cdt also cheapest** — its verbose per-node dump carries product texts that lean snapshots drop, which value-based targeting needs. We publish this as a known tradeoff of text clipping: total-token savings mean nothing unless per-point-of-accuracy cost holds, and this suite is the canary (fix direction benchmarked: attach sibling-text summaries only when same-name candidates conflict).\n\nHITL confirmation closes a loop: any gated call returns `CONFIRMATION_REQUIRED` once; after the user approves in chat, the agent re-calls with `confirmed=true` (applies to HITL rules, `browser_evaluate`, `browser_network_body`).\n\n## HTTP transport (remote / multi-client)\n\nDefault is stdio (single client). For remote or multi-client use, run a streamable-HTTP server:\n\n```bash\nBROWSER_TRANSPORT=http BROWSER_HTTP_PORT=8817 nexus-browser-mcp\n```\n\nEach MCP session gets an isolated `session_id` (isolated contexts per task, as usual). Safety rule: binding a non-localhost address without `BROWSER_HTTP_TOKEN` **refuses to start** — an unauthenticated browser-control port is a footgun; with a token set, requests must send `Authorization: Bearer <token>`.\n\nStreaming content (AI replies etc.): `browser_read(wait_stable=true)` waits for DOM quiet and reads the full text in one call; `browser_read(selector=..., follow=true)` tracks incrementally and returns only new content per call (`full=true` returns the whole buffer). `browser_wait_stable` / `browser_wait_ms` provide event-driven and fixed-duration waiting primitives.\n\nSnapshot diff: a repeated `browser_snapshot` whose tree is node-for-node identical to the last one (refs excluded — Playwright renumbers them per generation) returns a ~120-char `[no change]` notice instead of the full tree, and previously issued refs remain valid via generation chaining; `diff=false` forces a full snapshot. Any real change (content, box, attributes) yields the full snapshot — no partial merges, no stale views.\n\nMost tools accept an optional `task_id` (defaults to a shared `default` task). See usage guides in `docs/` (Chinese).\n\n## Development\n\n```bash\nuv venv\nuv pip install -e \".[dev]\"\npython -m pytest tests -q\nruff check src tests\npython -m smokes.test_e2e           # real-browser smoke\npython -m smokes.test_e2e_interact  # forms + multi-task smoke\npython -m smokes.test_e2e_observability  # console/exception/network observability smoke\n```\n\n## License\n\nMIT\n",
  "bytes": 14968,
  "sha": "fa999c93d9d4137c9c2a4a395c4bab9421bc91bfd5adcb08afc592300664170e",
  "repo_slug": "paipaipai666/nexus-browser-mcp",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_paipaipai666_nexus_browser_mcp_c2a5058a/readme"
}