Skip to main content
Glama
README.md
# brave-mcp

> Türkçe: [README.tr.md](README.tr.md)

A local MCP server that lets Claude Code drive the **real Brave browser on your
machine** — the tabs, windows, sessions and extensions you already use. No
throwaway profile, no second browser, no cloud relay.

It exposes 98 tools: tab and window management, page reading and interaction,
trusted (isTrusted) mouse and keyboard input, cookies, history, bookmarks,
downloads, clipboard — and the ability to **list and interact with the
extensions installed in your profile**.

## How it works

```
Claude Code ──stdio (MCP)──► brave-mcp (Python) ──ws://127.0.0.1:8765──► Brave extension
                                                                              │
                                                              chrome.* + chrome.debugger
                                                                              ▼
                                                              REAL profile / extensions
```

One Python process does two jobs: an MCP stdio server, and a small WebSocket +
HTTP server bound to `127.0.0.1`. An MV3 extension installed in your real profile
connects **outward** to that server, and every browser action runs inside the
extension through the `chrome.*` APIs. Two Claude Code sessions can share the
same browser (the extension opens a separate socket to each server it finds).

### Why not `--remote-debugging-port`

Chromium 136+ **ignores that flag on the default user profile** (verified
empirically: CDP only opens when a different `--user-data-dir` is given). A
different profile is not "my real account". The extension inventory also cannot
be read from disk (records live in the HMAC-signed `Secure Preferences`), so
`chrome.management` is required to see extensions at all. The extension bridge is
the only path that satisfies both.

## Install

### 1. Python side

```bash
git clone https://github.com/niyoseris/brave-mcp.git ~/brave-mcp
cd ~/brave-mcp
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"

.venv/bin/python -m brave_mcp --check     # port + token + tool count (stderr)
.venv/bin/pytest -q                        # 61 tests
```

On first run `--check` creates `~/.brave-mcp/config.json` (mode `0600`) with a
token. The token is **never** printed; it reaches the extension only inside the
`hello` frame.

### 2. Launch Brave with the debugger flag

The flag needed to attach a debugger to *another* extension can only be given
at **launch time**:

```bash
./scripts/brave-with-mcp-flag.sh
# make it a habit in ~/.zshrc:
#   alias brave="$HOME/brave-mcp/scripts/brave-with-mcp-flag.sh"
```

The flag does **not** alter your real profile, sessions or extensions; it only
widens the debugging API's scope. Everything works without it too — only the
"look inside another extension" features then return `NeedsSilentDebugger`.

### 3. Load the extension

`brave://extensions` → enable **Developer mode** → **Load unpacked** →
`~/brave-mcp/extension`

### 4. Pair

Open the extension's options page → **Pair (one click)**. It scans ports
8765–8774, finds the server answering with `app: "brave-mcp"`, writes the token
to `chrome.storage.local` and connects. You should see a green dot.

### 5. Register with Claude Code

```bash
claude mcp add --scope user brave -e BRAVE_MCP_TOOLSET=full -- \
  "$HOME/brave-mcp/.venv/bin/python" -m brave_mcp
```

Then **restart Claude Code** (MCP servers load at session start).

## Usage

Start with `browser_info` and `browser_ping`; `brave_list_apis` lists the
implemented methods. A typical flow:

```
tab_list                       → open tabs
tab_open("https://example.com")
page_read                      → page text
page_screenshot                → image (returned as a model block)
page_click("#submit")          → real click (isTrusted)
ext_list                       → installed extensions + permissions
ext_open_popup("<wallet id>")  → open a popup as a tab (mode="tab" by default)
```

**Tool groups** (98 tools total): `system`, `tabs`, `windows`, `page`, `input`,
`extensions`, `cookies`, `history`, `bookmarks`, `downloads`, `raw`.

`BRAVE_MCP_TOOLSET=core` hides the advanced groups (cookies/history/bookmarks/
downloads/raw plus some extension tools) to cut context cost.

### Two safety gates

- **`confirm:true`** — destructive tools (`tab_close`, `cookie_clear`,
  `ext_uninstall`, `bookmark_remove`, `chrome_call`, …) never touch the browser
  without it; they return `{"ok": false, "kind": "ConfirmRequired"}`.
- **Wallet gate** — when the target tab's origin is a known crypto wallet
  (Phantom, Solflare, Keplr, Bybit), clicks/typing/JS evaluation require
  `confirm`. The gate lives **in the extension** (`extension/lib/guard.js`),
  because the decision needs the tab's *current* URL — so indirect routes like
  `chrome_call` and `cdp_send` are covered too. The wallet's **own approval flow
  is never bypassed**; only its real UI is driven.

### Local network hardening

The server binds to `127.0.0.1` only. The `Host` header must be exactly
`127.0.0.1:<port>` / `localhost:<port>` (defeats DNS rebinding), **no CORS header
is ever returned** (a web page cannot read the body), the token never appears in
URLs, and a WebSocket upgrade that does not present a valid `hello` within 3
seconds is closed. On first pairing the extension id is pinned via TOFU.

## Security model and risks

This tool intentionally exposes your **signed-in browsing session** to an agent.
Treat it accordingly:

- Any page the agent reads can carry prompt-injection text. Keep the toolset
  (`BRAVE_MCP_TOOLSET=core`) and the site permissions as narrow as your workflow
  allows, and review actions that leave the machine.
- Cookie, history and bookmark tools mean a compromised or confused agent can
  read far more than page text. Leave `BRAVE_MCP_TOOLSET` at `core` unless you
  need them.
- The bridge is local, but the *browser* is not sandboxed: a destructive tool is
  one `confirm` away, and the wallet gate is a guardrail, not a security
  boundary against a malicious model.

## How it compares

| | Real profile | Runs locally / no account | Extension inventory | API surface |
|---|---|---|---|---|
| **brave-mcp** (this) | yes | yes | yes | tabs, page, input, cookies, history, bookmarks, downloads, extensions, CDP |
| Claude in Chrome (official) | yes | no — via `bridge.claudeusercontent.com`, requires a paid plan and `/login` | no | tabs, page actions, console, GIF, uploads |
| Chrome DevTools MCP (Google) | opt-in | yes | no | debugging, tracing, Lighthouse |
| Playwright MCP (Microsoft) | opt-in (`--extension`) | yes | no | E2E/automation, cross-browser |
| browsermcp.io and similar | yes | yes | no | real-profile automation |

## Troubleshooting

**"brave-mcp module not found" / the `pytest` console script does not work**
On macOS, editable installs under iCloud/Desktop can have the `hidden` flag set
on their `.pth` files, and Python 3.12 `site.py` **skips hidden `.pth` files**.
Check and fix:

```bash
ls -lO .venv/lib/python*/site-packages/__editable__*   # is 'hidden' there?
chflags nohidden .venv/lib/python*/site-packages/__editable__*
```

`pyproject.toml` also sets `pythonpath = ["."]` as insurance for the tests.

**The extension says "not connected"** — Is Claude Code running? Does the MCP
entry show in `claude mcp list`? Try "Reconnect" in the extension options.

**`NeedsSilentDebugger`** — Brave was started without the flag. Quit it and
relaunch with `scripts/brave-with-mcp-flag.sh`.

**`DebuggerBusy`** — DevTools is open on that tab; close it or use another tab.
After 60 seconds idle the attachment is released and the "DevTools is debugging"
bar disappears by itself.

**`NotConnected`** — the browser side is not answering. Tab ids are valid for the
session; refresh them with `tab_list`.

## Repository layout

```
brave_mcp/            Python MCP server (config, protocol, bridge, tools/*)
extension/            Brave MV3 extension (background.js, lib/*, handlers/*, options, popup)
scripts/              brave-with-mcp-flag.sh, gen_extension_key.sh, static JS checks
tests/                protocol + bridge + tool contract + coverage tests
```

## Development notes

- Python comments/docstrings are Turkish; tool names and descriptions are English
  (the `inkscape-mcp` convention). stdout carries only the MCP protocol; logs go
  to stderr.
- Errors are returned as **data**, not exceptions: `{"ok": false, "kind": …}` with
  `kind` from a closed set (see `brave_mcp/protocol.py`,
  `extension/lib/errors.js`).
- `tests/test_coverage.py` compares the 96 wire methods the extension reports
  with the MCP tool list; two tools (`browser_info`, `browser_events_drain`)
  deliberately never reach the extension and run in the bridge.
- `./scripts/check_extension_js.sh` runs two static checks on the extension JS:
  syntax, and that every module actually imports under a fake `chrome`
  (catching a missing export that would otherwise only blow up at runtime in the
  browser).

## Access to wallet pages (a measured limit)

`chrome-extension://` is **not a valid match-pattern scheme** — putting it in
`host_permissions` is rejected by Brave as *"URL pattern is malformed"*, and
`<all_urls>` does not cover it either. So when a wallet popup is opened as a tab,
`chrome.scripting` **cannot** reach it.

The read tools therefore do not depend on a single path: `run()` in `lib/dom.js`
tries `scripting` first and, on `NotAllowed`, runs the same self-contained
function through `chrome.debugger`. `chrome.debugger` is attach-based, not
permission-based. Result: `page_read`, `page_query`, `page_find_text`,
`page_click`, `page_eval`, `page_screenshot(full_page=true)` and trusted input
work on wallet pages too. The cost is the "DevTools is debugging" bar on that tab
(it disappears after 60 seconds idle).

`page_screenshot` uses `captureVisibleTab` in **visible** mode, which needs the
host permission; on a wallet page use `full_page=true` — the tool says so in its
error message.

## Known limits

- The wallet's own approval flow is not bypassed; signing a transaction still
  needs the user's approval.
- `chrome.action.openPopup()` only opens the extension's **own** popup; for
  another extension's popup use `ext_open_popup(mode="tab")`.
- The debugger cannot attach to `chrome://` or Chrome Web Store pages (the
  browser blocks it).
- `captureVisibleTab` captures the window's active tab; the tool activates the
  tab for this first.
- The CDP read path sees only the **main frame** (no `allFrames`).

## License

MIT — see [LICENSE](LICENSE).