chrome-control-mcp
# chrome-control-mcp
Drive tabs in your **regular Chrome browser** from AI assistants (Antigravity, Claude Desktop, Claude Code, Codex, Cursor) over the **Model Context Protocol (MCP)** — using a **Manifest V3 Chrome Extension** instead of `--remote-debugging-port` or a separate automation Chrome profile.
Because it runs as a standard Chrome extension inside your everyday signed-in browser session, you keep your existing logins, cookies, and workspace tabs while controlling exactly which tabs an AI assistant can access.
---
## Why an Extension Instead of CDP?
- **Uses your real Chrome window**: No `--remote-debugging-port`, no detached automation binary, and no separate Google sign-in profile.
- **Explicit per-tab consent**: Starts in **Attached Tabs Only** mode — only tabs you attach from the extension popup (or open via `browser_open_tab`) can be inspected or controlled. You can switch to **All Tabs** mode anytime from the popup.
- **Visual indicators**: The Chrome toolbar badge shows `ON` when connected, `MCP` (green) on attached tabs, and `ALL` when All Tabs mode is active.
- **Multi-client safe**: Multiple MCP apps/windows running simultaneously share one local WebSocket bridge automatically via a **leader/follower** HTTP proxy on `127.0.0.1`.
- **Zero-build extension**: `extension/` is plain JavaScript/HTML/CSS ready for **Load unpacked** in `chrome://extensions`.
---
## Architecture
```text
+-----------------------+
| Antigravity / Claude |
| Codex / Cursor |
+-----------+-----------+
| MCP (stdio)
v
+-----------------------+ HTTP /rpc (follower -> leader)
| chrome-control-mcp | <------------------------------------+
| (Node.js TypeScript) | |
+-----------+-----------+ |
| ws://127.0.0.1:19222/ws |
| Auth: 256-bit Bearer/query token |
| Origin check: chrome-extension://* only |
v |
+-----------------------+ |
| Chrome MV3 Extension | (existing Chrome profile + sessions) |
| - background.js | |
| - content.js (on-dem.)| |
| - popup UI | |
+-----------------------+
```
---
## Quick Start
### 1. Build the MCP server
Requires **Node.js 22+** and **Google Chrome** (or any Chromium browser supporting Manifest V3).
```bash
git clone https://github.com/<your-username>/chrome-control-mcp.git
cd chrome-control-mcp
npm install
npm run build
```
> **Windows PowerShell note**: If PowerShell blocks `npm` due to script execution policy, run `npm.cmd install` and `npm.cmd run build` (or run from Command Prompt / Git Bash).
### 2. Generate & print your local auth token
```bash
npm run token
# Windows PowerShell fallback: npm.cmd run token (or: node dist/index.js --print-token)
```
This creates (or reads) a 256-bit hex secret in `~/.chrome-control-mcp/token` (`%USERPROFILE%\.chrome-control-mcp\token` on Windows) and prints:
```text
Token: <64-char-hex-token>
Token file: ...
WebSocket URL: ws://127.0.0.1:19222/ws
```
### 3. Load the Chrome Extension
1. Open `chrome://extensions` in your regular Chrome browser.
2. Turn on **Developer mode** (top-right toggle).
3. Click **Load unpacked** and select this repository's `extension/` folder.
4. Pin **Chrome Control MCP** to your Chrome toolbar.
5. Click the extension icon, paste your **Auth Token** (port defaults to `19222`), and click **Connect**.
6. Open a webpage you want to work with and click **Attach Current Tab** in the popup.
### 4. Add the MCP server to your AI client
Replace `/absolute/path/to/chrome-control-mcp` with the actual path on your machine.
#### Antigravity (`mcp_config.json`)
Open **Manage MCP Servers → View raw config** (or `~/.gemini/antigravity/mcp_config.json` / `.agents/mcp_config.json`) and add:
```json
{
"mcpServers": {
"chrome-control": {
"command": "node",
"args": ["/absolute/path/to/chrome-control-mcp/dist/index.js"]
}
}
}
```
Windows example (`mcp_config.json` or `claude_desktop_config.json`):
```json
{
"mcpServers": {
"chrome-control": {
"command": "C:\\Program Files\\nodejs\\node.exe",
"args": ["C:\\Users\\you\\chrome-control-mcp\\dist\\index.js"]
}
}
}
```
#### Claude Desktop (`claude_desktop_config.json`)
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
Use the same `"mcpServers"` JSON block above.
#### Claude Code
```bash
claude mcp add --scope user chrome-control -- node /absolute/path/to/chrome-control-mcp/dist/index.js
```
#### Codex (`~/.codex/config.toml` / `%USERPROFILE%\.codex\config.toml`)
```toml
[mcp_servers.chrome-control]
command = "node"
args = ["/absolute/path/to/chrome-control-mcp/dist/index.js"]
```
#### Cursor (`.cursor/mcp.json` or global MCP settings)
Use the same `"mcpServers"` JSON configuration as Antigravity / Claude Desktop.
Restart your MCP client, make sure the extension shows **Connected**, and ask: *"Check browser_status and snapshot my attached tab."*
---
## Security Model & Scope
- **Loopback only**: The local server binds strictly to `127.0.0.1` (never `0.0.0.0`).
- **256-bit secret token**: Saved with `0600` file mode and verified using `crypto.timingSafeEqual`.
- **CSWSH protection**: WebSocket upgrade requests that include an `Origin` header are rejected with `403 Forbidden` unless the origin begins with `chrome-extension://`. Any random webpage trying to connect to `ws://127.0.0.1:19222` is blocked.
- **Explicit tab consent**: Defaults to `attached_only` mode so unattached personal tabs remain isolated until you attach them (or switch to `all_tabs`).
- **Restricted browser URLs blocked**: Internal pages (`chrome://`, `chrome-extension://`, `edge://`, `about:`, `devtools://`, Chrome Web Store) cannot be scripted.
- **Sanctioned APIs only**: Built solely on documented Chrome Manifest V3 extension APIs (`tabs`, `scripting`, `storage`, `alarms`, `downloads`). It does **not** spoof browser fingerprints or bypass CAPTCHAs, anti-bot checks, login walls, or platform quotas — complete any sign-in or verification challenge manually in Chrome.
---
## MCP Tools Reference (17 Tools)
| Tool | Purpose |
|---|---|
| `browser_status` | Check extension connection, control mode, attached tab IDs, and local bridge config (plus setup steps when disconnected). |
| `browser_list_tabs` | List open Chrome tabs with `id`, `title`, `url`, `active`, `pinned`, `status`, and `attached` flags. |
| `browser_open_tab` | Open a URL in a new Chrome tab (auto-attaches by default when `attach` is true). |
| `browser_switch_tab` | Activate a tab by `tabId` and focus its Chrome window. |
| `browser_close_tab` | Close a controlled tab by `tabId`. |
| `browser_navigate` | Navigate (`goto` a URL, `back`, `forward`, or `reload`) and optionally wait for page load. |
| `browser_snapshot` | Walk visible DOM and open Shadow DOM interactive elements, returning short refs (`e1`, `e2`, ...) plus optional page text. |
| `browser_click` | Click, double-click, right-click, or hover an element by snapshot `ref`, CSS `selector`, `text`, or `role`. |
| `browser_type` | Type into `<input>`, `<textarea>`, or `contenteditable` / `.ProseMirror` editors (compatible with React/Vue controlled inputs). |
| `browser_press_key` | Send keyboard events (`Enter`, `Escape`, `Tab`, `ArrowDown`, etc.) with optional `ctrl`/`shift`/`alt`/`meta` modifiers. |
| `browser_select_option` | Select a `<select>` option by `value` or visible `label`. |
| `browser_scroll` | Scroll the page or a container (`up`, `down`, `left`, `right`, `top`, `bottom`), or scroll a target element into view. |
| `browser_wait` | Wait for a selector or text to reach `visible`, `hidden`, `attached`, or `detached` state, or pause for `ms`. |
| `browser_screenshot` | Capture the visible tab (`png` or `jpeg`), return an MCP image block directly, and optionally save to `savePath`. |
| `browser_get_text` | Read visible text or a specific HTML attribute from an element or the entire page. |
| `browser_download` | Trigger a Chrome download using your browser session/cookies, list recent downloads, or check a download's status. |
| `browser_upload_file` | Read a local file (up to 25 MB) and attach it to an `<input type="file">` element on the page. |
---
## Configuration (Environment Variables)
| Variable | Default | Purpose |
|---|---|---|
| `CHROME_CONTROL_MCP_PORT` | `19222` | Localhost WebSocket & follower HTTP port. |
| `CHROME_CONTROL_MCP_HOME` | `~/.chrome-control-mcp` | Directory storing the generated `token` file. |
| `CHROME_CONTROL_MCP_TOKEN` | *(auto-generated)* | Optional override token instead of reading `<home>/token`. |
---
## Development & Testing
```bash
npm run build # Compile src/*.ts -> dist/*.js
npm test # Run extension syntax, bridge security/RPC, and end-to-end stdio MCP tests
npm run icons # Regenerate extension/icons/icon{16,48,128}.png
```
## License
[MIT](LICENSE)
TDQS
Scored across 17 tools
Each tool targets a distinct browser concern: tab lifecycle (open/switch/close/list), navigation, inspection (snapshot/get_text/screenshot), and interaction (click/type/press_key/scroll/select_option). The only mild overlaps are browser_navigate vs browser_open_tab and browser_get_text vs browser_snapshot's text option, but descriptions make the intended boundaries clear. browser_download bundles download/list/status actions, but they are variants of one download concept rather than ambiguous alternatives.
Every tool follows the same browser_verb_noun snake_case pattern (browser_list_tabs, browser_open_tab, browser_press_key). No camelCase or stylistic deviations anywhere in the set.
17 tools is slightly above the comfortable band but each one maps to a real browser-automation primitive with no filler. The set is well scoped for a Chrome control server, just on the heavier side.
Core workflows are covered end-to-end: connection status, tab management, navigation, snapshot-based inspection, rich interaction, waiting, screenshots, and file transfer. Notable gaps remain around JS evaluation, cookie/localStorage access, and dialog (alert/confirm) handling, which agents may need for complete automation.