# Spectra — a native Rust browser MCP server [![License: PolyForm Shield 1.0.0](https://img.shields.io/badge/license-PolyForm%20Shield%201.0.0-blue)](LICENSE) [![Rust](https://img.shields.io/badge/rust-2021-orange?logo=rust)](https://www.rust-lang.org) [![MCP](https://img.shields.io/badge/protocol-MCP-green)](https://modelcontextprotocol.io) Spectra is a source-available, free-to-use MCP server that gives AI agents fast, token-efficient control of Chrome over the Chrome DevTools Protocol. Spectra drives Chrome directly through the Chrome DevTools Protocol (CDP), without Playwright's abstraction layer, to give an AI agent (Claude Code or any MCP client) fast, information-dense browser control that can be extended per project. See [`docs/COMPARISON.md`](docs/COMPARISON.md) for the measured comparison against Playwright MCP on a real application (the document is written in French; it opens with an English summary). A French version of this README is available in [`README.fr.md`](README.fr.md). ## Why - **Native Rust binary**: ~27 MB of RAM for the server process (versus ~130 MB for an equivalent Node.js process), no runtime to install. - **Direct CDP**: no client → relay server → browser double hop. - **Condensed snapshot**: pruned accessibility tree (presentational roles removed) with short `[eN]` refs; a screenshot is not the only source of truth. - **Extensible per project**: each repository can define its own scenarios (`.spectra/recipes/*.mjs`) without ever recompiling the server. - **Multi-session**: drives several Chrome instances in parallel (configurable limit), useful to simulate multiple users. - **Native Core Web Vitals**: LCP/CLS/FCP/TTFB measured through the browser's native APIs (`PerformanceObserver`), with no external dependency (no Lighthouse, no web-vitals.js). - **Secure by construction**: stdio transport only (`rmcp` feature `transport-io`, never HTTP/SSE). No local network socket is ever opened, which structurally eliminates the whole class of DNS rebinding vulnerabilities that affected other browser MCP servers exposing a local HTTP transport (e.g. CVE-2025-9611 on Playwright MCP). Nothing to configure, nothing to audit on this point: the attack vector simply does not exist in this architecture. ## Installation ### Prerequisites - Rust (2021 edition, stable toolchain) — `rustup` with the `x86_64-pc-windows-msvc` target - On Windows: Visual Studio Build Tools with the **Desktop development with C++** workload (the MSVC compiler) **and** the **Windows SDK — Desktop C++ x64/x86** component (it contains `kernel32.lib` and the other Win32 libraries; often missing from a minimal Build Tools installation, so add it explicitly) - Node.js **22+** on the PATH (only required for `browser_run_recipe`, degrades gracefully if absent). The recipe runtime (`recipe-runner.mjs`) uses Node's native global `WebSocket`, which is only stable from version 22; on an earlier version, `browser_run_recipe` would fail with `WebSocket is not defined` - Google Chrome installed (detected automatically in the standard locations) ### Build ```powershell cargo build --release ``` The `release` profile uses `lto = "thin"` rather than `lto = true` (fat LTO). Full LTO crashed LLVM with an out-of-memory error on a standard development machine while this project was being tuned; `thin` captures most of the performance gain without that risk. The resulting binary is at `target/release/spectra-server.exe`. ### Permanent installation ```powershell New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.spectra\bin" Copy-Item "target\release\spectra-server.exe" "$env:USERPROFILE\.spectra\bin\spectra-server.exe" ``` ## Enabling it in Claude Code Manually add the following entry to your MCP configuration (`~/.claude.json` or the equivalent for your platform, `mcpServers` section): ```json { "mcpServers": { "spectra": { "command": "%USERPROFILE%\\.spectra\\bin\\spectra-server.exe" } } } ``` If your client does not expand environment variables in this field, use the absolute path of the installed binary instead. Once added, `/mcp` in Claude Code should list `spectra` with its 38 tools available (catalog below). ## Emergency cleanup If test Chrome instances pile up (this happens when an MCP client crashes without shutting the server down cleanly): ```powershell powershell -File scripts\kill-all-spectra.ps1 ``` This script targets only the Chrome processes launched by Spectra (identified by their `--user-data-dir` under `%LOCALAPPDATA%\Spectra\profiles`); it never touches your personal Chrome. Alternative from within Claude Code, without leaving the conversation: ``` browser_sessions(action="close_all") ``` ## Environment variables | Variable | Purpose | |---|---| | `SPECTRA_MAX_SESSIONS` | Maximum number of simultaneous Chrome sessions (default: 6) | | `SPECTRA_ALLOW_HOSTS` | Internal hosts allowed despite the network policy (`localhost:8080,192.168.1.20:*,*.dev.test`). See [`docs/SECURITY.md`](docs/SECURITY.md) | | `SPECTRA_DIALOG_TIMEOUT_S` | Seconds before an unanswered `confirm`/`prompt`/`beforeunload` is refused (default: 120) | | `SPECTRA_CHROME_PATH` | Explicit path to a Chrome/Chromium binary, if Spectra does not find it automatically in the standard locations | | `SPECTRA_MINIMAL_CHROME` | Set to `0` to disable the 7 additional launch flags (GPU, notifications, etc. — see docs/COMPARISON.md, section V10) that reduce Chrome's RAM footprint by about 4%. Enabled by default | | `SPECTRA_WINDOW_SIZE` | Window + CDP viewport resolution, format `"1920x1080"` (default: `1920x1080`, dense 16:9) | | `SPECTRA_PREWARM` | Set to `1` to pre-warm a Chrome as soon as the server starts (20 s TTL if not consumed). Disabled by default: no Chrome opens until an explicit `browser_launch`/`browser_navigate` is called | | `SPECTRA_STEALTH` | Set to `1` to disable the most visible automation-detection signals on the page side (`navigator.webdriver`, the "Chrome is being controlled" banner, disabled GPU), to drive a third-party site that blocks detected automated browsers. Disabled by default (`SPECTRA_MINIMAL_CHROME` remains the normal mode, optimized for performance rather than discretion). Combine with `ctx.addInitScript()` on the recipe side for a more thorough JS evasion script (hiding `navigator.plugins`, WebGL fingerprint, etc.). See [Responsible use](#responsible-use) | | `SPECTRA_USER_AGENT` | Custom user agent (useful in stealth mode — a default user agent containing `HeadlessChrome` is itself a detection signal); has no effect unless `SPECTRA_STEALTH` is enabled | ## Tool catalog 38 tools, all prefixed `browser_`. The exact list is the one returned by `tools/list` (the `#[tool(...)]` attributes in `crates/spectra-tools/src/server.rs`); `tests/smoke.mjs` fails if it differs from the list the test declares. Every tool that acts on a page accepts `project` (project key) and `session=` (agent session, see "Several agents in parallel"). Stable JSON formats: [`docs/FORMATS.md`](docs/FORMATS.md). | Tool | Description | |---|---| | `browser_launch` | Starts or attaches Chrome for the current project | | `browser_snapshot` | Captures the condensed accessibility tree (text + `[eN]` refs, with `[disabled]`/`[checked]`/`[expanded]`/... state when present). With `diff_only=true`, returns only a compact summary of nodes added/removed/changed since the previous snapshot of this page (structural diff by `backendDOMNodeId`, not by line text). With `check_a11y=true`, adds an `a11y_issues` list of basic accessibility problems detected. With `detail="compact"` or `"refs_only"`, reduces verbosity to save tokens (see `docs/COMPARISON.md`, section V8) | | `browser_navigate` | Navigates to a URL, waits for the application to mount | | `browser_click` | Clicks a referenced element. Supports `diff_only=true` | | `browser_type` | Types text, with an optional submit (Enter). Supports `diff_only=true` | | `browser_fill_form` | Fills several fields in a single call. Supports `diff_only=true` | | `browser_select_option` | Selects a `` | | `browser_run_recipe` | Runs a `.mjs` recipe from the current project | | `browser_recipe` | Replayable journeys without spending tokens (`.spectra/recipes/.json`): `record`, `stop`, `run`, `list`, `show`, `delete`, `expect`, `expect_not` | | `browser_suite` | Replays several recipes in parallel (tabs of a single Chrome), with `setup` (sign-in) and optional isolation | | `browser_prove` | Replays a recipe and writes a proof folder (`proof.json`, before/after screenshots, console errors, failed requests). Format `spectra.proof/1` | | `browser_hmr` | Waits for hot reload (Vite, webpack) after an edit: `update`, `full-reload`, `error`, `timeout`, `no-hmr`. Format `spectra.hmr/1` | | `browser_design_review` | Design review from a JSON style profile: widths, light/dark, measurable checks, findings by severity. Format `spectra.design-review/1` (see [`docs/DESIGN_REVIEW.md`](docs/DESIGN_REVIEW.md)) | | `browser_render` | Renders a URL with JavaScript in an isolated context (internal network refused): final HTML, text, JSON responses, written to a file. Format `spectra.render/1` ([`docs/RENDER.md`](docs/RENDER.md)) | | `browser_dialog` | Pending JavaScript dialog (`confirm`, `prompt`, `beforeunload`): `status`, `accept`, `dismiss` (+ `text`). Never accepted automatically | | `browser_sessions` | `list`, `end` (closes YOUR agent session), `close` (one project), `close_all`, `gc` | | `browser_report` | Compiles the session log (navigations, actions, errors, dialogs) into a structured report | | `browser_act_sequence` | Runs a sequence of actions (`click`/`type`/`select_option`/`hover`/`press`) in a single call, without going back through a reasoning turn between steps. With `diff_only=true`, adds a compact summary of the change (captured once, after the last step) | | `browser_storage_state` | Exports (`action="export"`) or re-injects (`action="import"`) cookies + localStorage + sessionStorage of the active page, so a test session does not have to replay a full sign-in flow on an authenticated app | | `browser_drag` | Drags one element (`from_ref`) onto another (`to_ref`): reorder a list, move a kanban card. Progressive mouse movement (not a teleport) so that the pointer sensors of JS DnD libraries (dnd-kit, react-dnd, sortablejs) arm correctly | ## Per-project extensibility Create `/.spectra/recipes/.mjs`: ```js export default async function loginAdmin(ctx, args) { await ctx.navigate(`${process.env.SPECTRA_BASE_URL}/login`); const snap = await ctx.snapshot(); const emailRef = ctx.findRef(snap, { role: "textbox", name: /email/i }); await ctx.type(emailRef, args.email); const pwRef = ctx.findRef(snap, { role: "textbox", name: /password/i }); await ctx.type(pwRef, args.password, { submit: true }); await ctx.waitFor({ text: "Dashboard", timeoutMs: 8000 }); return { loggedIn: true }; } ``` Call from Claude Code: ``` browser_run_recipe(project="my-project", recipe="login_admin", args={email: "test@example.com", password: "..."}) ``` The Node runtime (`recipe-runner.mjs`, a minimal CDP client with no npm dependency) is embedded in the binary and auto-installed into `%LOCALAPPDATA%\Spectra\runtime\` on first call — nothing to install manually. Secrets: pass them explicitly in the `args` of `browser_run_recipe` (there is no automatic `.env`/`.gitignore` mechanism for now). ## Multi-session management By default, up to **6 simultaneous Chrome sessions** (configurable via `SPECTRA_MAX_SESSIONS`), one per project key. A second `browser_launch` on the same project always reuses the existing session rather than spawning a new one. Useful for driving several browsers in parallel — for example, simulating several users testing collaborative editing on the same application. ### Several agents in parallel: `session=` For several agents to share one Chrome without getting in each other's way, each picks a session identifier (`session=`), gives it to `browser_launch`, then passes it again on **every** tool. The agent then reaches only ITS tabs; the main session never reaches an agent's tabs; neither `clean` nor the tab cap ever closes a tab that belongs to the user. It ends with `browser_sessions action=end`. Without `session`, nothing changes: main session, default project. ``` browser_launch(session="agent-a", headless=true) # tabs belong to agent-a only browser_launch(session="agent-b", isolated=true) # + separate cookies and storage browser_navigate(session="agent-a", url="...") -> browser_click(session="agent-a", ref="...") browser_navigate(session="agent-b", url="...") -> browser_snapshot(session="agent-b") browser_sessions(action="end", session="agent-a") # closes its tabs, frees its memory ``` `browser_launch` options with `session`: `isolated` (separate browsing context) and `owner_pid` (the session closes when that process disappears). A garbage collector also closes idle sessions and the tabs of a vanished process (`browser_sessions action=gc` forces it). `project` stays the key of the Chrome (and of the `.spectra/` folder holding recipes, proofs and visual references): use it to target another project, not to share a Chrome between agents. Tests: `tests/agents.mjs`. ## Persistent authentication On an authenticated app, replaying a full sign-in flow (snapshot + type x 2 + click + wait_for) at the start of every test session is expensive in tool calls and tokens. `browser_storage_state` captures cookies + localStorage + sessionStorage once after a successful sign-in, and they can then be re-injected into any future session: ``` # once, after a successful manual/scripted sign-in state = browser_storage_state(action="export") # in a future session (same browser or not): browser_navigate(url="https://my-app.example.com/") # first navigate to the target origin browser_storage_state(action="import", state=state) # cookies + localStorage + sessionStorage restored browser_navigate(url="https://my-app.example.com/dashboard") # already signed in ``` localStorage/sessionStorage are inherently scoped to the browser origin, so `import` must be called AFTER navigating to the target origin, otherwise they land on the wrong origin (same constraint as Playwright's `storageState`). Cookies do not have this constraint (explicitly scoped through `domain`/`path`). ## JS dialogs (alert/confirm/prompt) An `alert()` (a single button, no effect) is closed immediately and logged. A `confirm()`, `prompt()` or `beforeunload` is **never accepted automatically**: it stays pending, tools that act on the page stop with an error describing the question, and the agent decides with `browser_dialog` (`action=accept` or `dismiss`, `text` for a prompt). With no answer within `SPECTRA_DIALOG_TIMEOUT_S` seconds (default 120), the question is refused. Every dialog stays visible afterwards through `browser_dialog action=status` and `browser_report` (`summary.dialogs`). ## Security Visited pages are untrusted data. By default, the internal network (localhost, 10/8, 172.16/12, 192.168/16, 169.254/16, `file:`, exotic schemes) is refused for navigation, tabs, recipes and `browser_render`, redirects and iframes included. Only the owner can override this, through configuration: `SPECTRA_ALLOW_HOSTS=localhost:8080,127.0.0.1:*` (never through a tool parameter). Details, known limits, sanitized recipe names: [`docs/SECURITY.md`](docs/SECURITY.md). ## Startup pre-warming When `SPECTRA_PREWARM=1` is set, Spectra silently pre-warms a Chrome for the current directory (the most likely project) as soon as the server starts, without blocking the MCP handshake. If the first `browser_launch`/`browser_navigate` targets that same project, it instantly picks up this already-started Chrome. If it is never consumed, it closes automatically after 20 seconds — no risk of silent accumulation. ## Tests ``` node tests/smoke.mjs # the 38 tools, one by one node tests/security.mjs # network policy, JS dialogs, recipe names, console stacks node tests/agents.mjs # agent sessions: isolation, closing, garbage collection, parallelism (--no-measure skips the measurement) ``` End-to-end tests: real MCP stdio protocol (no mock), real headless Chrome, pages served over local http. They compile nothing: build the binary first (`cargo build --release -p spectra-server`). The default binary is `target/release/spectra-server(.exe)`; `SPECTRA_EXE=path/to/spectra-server.exe` targets another one, and `SPECTRA_TEST_VERBOSE=1` prints the server logs. The shared MCP client is `tests/lib/mcp.mjs`. The test servers allow their local page through `SPECTRA_ALLOW_HOSTS` (otherwise the network policy refuses it). `tests/smoke.mjs` starts with a **coverage test**: the server's `tools/list` must be exactly the set of tools the file declares as covered (or excluded, with the reason written down). Adding or removing a tool without updating that file fails the suite, and every declared tool must have been called with an assertion on the real result. ## Architecture ``` crates/ ├── spectra-cdp/ # CDP client (launcher, session, snapshot, actions, network/console observers) ├── spectra-tools/ # Exposed MCP tools (schemas, rmcp routing) └── spectra-server/ # Binary, MCP stdio transport runtime/ └── recipe-runner.mjs # Minimal JS CDP client (embedded in the binary via include_str!, auto-installed) scripts/ └── kill-all-spectra.ps1 # Emergency cleanup of test Chrome instances ``` Main libraries: `chromiumoxide` (CDP client), `rmcp` (the official Rust MCP SDK), `tokio` (async runtime). ## Development history and known limitations See [`docs/COMPARISON.md`](docs/COMPARISON.md) — a measured comparison against Playwright MCP and an honest account of each development wave (V1 to today), including abandoned attempts and bugs found by actively testing against a real application. ## Responsible use `SPECTRA_STEALTH` and the other anti-detection features exist only to test and automate sites that you have the right to automate access to. Respect the terms of service of the sites you interact with, and do not use Spectra to bypass access controls, scrape content you are not allowed to collect, or otherwise act against the rules that apply to a site. ## Contributing Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md). To report a vulnerability, see [SECURITY.md](SECURITY.md). ## License Free to use, including commercially. You may not use it to build a competing product or service. Contributions welcome. See [LICENSE](LICENSE) (PolyForm Shield 1.0.0). Source-available, not open source. ## More from AstroQuest - [Cortex](https://github.com/AstroQuestStudio/cortex) - [Thonny AI](https://github.com/AstroQuestStudio/thonny-ai) - [CATIA V5 MCP](https://github.com/AstroQuestStudio/catia-v5-mcp)