← Back to all articles

Cutting AI Browser MCP Tokens by 85.4% (174K -> 25K) & Running 160 Parallel Agents with an 848 KB Zero-Tokio Rust Server

Last week I wrote about building sessfork (MIT) to fork live Chrome/Edge login sessions (SQLite...

🌐 阅读中文版本 →
#Rust#AI Agents#MCP#Benchmarks
Links & cross-posts: DEV.to ↗ GitHub ↗
On this page

sessfork-mcp 4-way token & memory benchmark

Last week I wrote about building sessfork (MIT) to fork live Chrome/Edge login sessions (SQLite Cookies + LevelDB LocalStorage, including Windows Chrome v20 App-Bound Encryption) into background headless MCP browsers so AI coding agents stop hijacking your foreground window focus.

Once we got browser RAM down with a native Rust MCP server + lexmount/moli, an even bigger production bottleneck showed up immediately: input tokens and small-model retry loops.

Even if you cut browser memory by 90%, driving a web app through standard @playwright/mcp still hits two walls on every multi-step workflow:

  1. Context bloat that compounds quadratically: @playwright/mcp exposes 42 tool schemas (~7,239 tokens sent upfront on every turn) and dumps 15–25 KB accessibility snapshots after every click or type. Over just 8 steps on a realistic SaaS admin SPA, cumulative input tokens balloon to ~174K tokens — spilling 7 .yml files to disk and drowning smaller/cheaper or local models (Flash, Haiku, 7B–14B Ollama/vLLM).
  2. Silent dead clicks: When a model clicks a disabled, readonly, or validation-gated button, Playwright quietly returns the full 24 KB page tree again with zero feedback that nothing changed — trapping cheaper models in multi-turn retry loops.

To solve both memory and token burn at the protocol layer (without adding an LLM-in-the-middle), I built sessfork-mcp: a single ~848 KiB stripped, zero-Tokio, zero-Node.js Rust binary that speaks native Chrome DevTools Protocol (CDP).


Why Zero-Tokio / Zero-Node.js Rust?

Standard @playwright/mcp carries a ~270–300 MB Node.js wrapper per agent, 1.2–3.4 s cold startup, and injects Playwright’s JavaScript aria-snapshot helper into every renderer V8 heap.

sessfork-mcp compiles down to ~848 KiB depending only on serde, serde_json, and OS primitives (std::thread, std::net, and a pure-std RFC 6455 WebSocket client — no tokio, no async executor):

  • 2.8 ms cold MCP initialize and 2.9 MB flat RSS across 500 hot-reload cycles.
  • OS-native orphan freedom: Uses Unix FD 3/4 anonymous pipes (--remote-debugging-pipe with NUL-framed JSON; SIGKILL parent -> child exits in 11.9 ms, 0 orphans) and Windows Win32 Job Objects (JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE).
  • Universal --cdp-url attach: Connect to any local Chromium, chrome-headless-shell, or CEF instance without switching browser engines — guarded by a fail-closed loopback SSRF allowlist and Drop-guaranteed BrowserContext disposal (never kills the host browser).

What Changed in --compact --diff (Zero-Layout Protocol)

Many browser agents shrink pages by calling getBoundingClientRect() or taking screenshots. That forces a full layout/paint pass and defeats the point of lightweight engines like Moli. Instead, --compact --diff operates purely on CDP Accessibility.getFullAXTree:

  • Iterative explicit-stack AXTree distillation (src/ax.rs): Zero recursion (tested to 3,000 nested wrappers so hostile DOM depth never overflows the stack) and zero layout queries. Strips non-interactive boilerplate while preserving actionable controls, labels, values, disabled/checked/expanded states, and concise context headings.
  • Automatic active modal scoping: Detects open alertdialog / aria-modal="true" containers (including WAI-ARIA tabindex="-1" dialog wrappers without suppressing inner text) and scopes the observation to the active modal so background buttons stop distracting the model.
  • Persistent per-document RefRegistry: Maps backendDOMNodeId -> eN stably across same-page DOM updates (live-set pruned above 4,096 entries, reset on full page reload).
  • Action Receipts, +/- Diffs, and WARNING: NO_OP: After clicks or types, sessfork-mcp computes the diff against the previous distilled snapshot. If a click hits a disabled, readonly, or inert control and produces zero DOM delta, it returns a 288-byte WARNING: NO_OP receipt instead of re-sending 24 KB of unchanged page.

Verified Local Benchmarks (Apple Silicon 24 GB)

Every number below comes from 100% local loopback reproduction scripts in the repo (zero external network calls, zero Keychain prompts, zero API keys).

1. 8-Step Authenticated SaaS Admin SPA — Tokens & Memory (python3 scripts/bench_tokens.py)

Stack Upfront Schema 8-Step Obs Cumulative 8-Turn Input Saved Wall Peak RSS NO_OP Modal Scope
Chrome + Node @playwright/mcp (7 file spills) 7,239 tk 19,526 tk 174,114 tk baseline 4.07 s 585.3 MB No No
Chrome + Rust --cdp-url (default full YAML) 1,783 tk 28,909 tk 189,103 tk -8.6% 2.53 s 310.1 MB Yes No
Chrome + Rust --cdp-url --compact --diff 1,783 tk 2,012 tk 25,474 tk -85.4% 2.53 s 309.8 MB Yes Yes
Moli 1.1.27 + Rust --compact --diff 1,783 tk 2,012 tk 25,474 tk -85.4% 2.33 s 66.6 MB Yes Yes

Notice two things:

  • You do not have to leave Chrome to get the -85.4% (6.83×) token reduction — attaching sessfork-mcp --cdp-url --compact --diff to standard Chrome produces bit-for-bit identical token counts (25,474 tk), NO_OP detection, and modal isolation.
  • Pairing it with lexmount/moli adds an -88.6% RAM cut (585.3 MB -> 66.6 MB) and 1.74× faster wall time (4.07 s -> 2.33 s).

2. Multi-Agent Concurrency Ceiling on 24 GB (python3 scripts/bench_scale.py --swarm-ceiling)

Measured with Heavy-DOM isolated contexts (+0.0 MB swap, 0 leaked targets/orphans):

  • Chrome + Node @playwright/mcp: 10.63 GB already at 16 agents (~22–23 practical ceiling)
  • Chrome + Rust --cdp-url (pooled Chrome): 56 parallel agents (168/168 tasks in 3.85 s, 15.35 GB)
  • Moli + Rust Pipe (320 live procs): 160 parallel agents (480/480 tasks in 9.69 s, 14.94 GB)

Bonus systems finding while stress-testing 96 single-process contexts: we hit and reported a real POSIX FD_SETSIZE (1024) / libcurl descriptor limit upstream in lexmount/moli#3803.


Security-by-Omission & Runnable Verification

Forking authenticated sessions is sensitive by definition, so we designed around narrow blast radius rather than trust-the-prompt:

  • Zero raw credential read tools in MCP tools/list: Agents can use forked auth state inside the browser context, but cannot call browser_cookie_list or browser_localstorage_get to exfiltrate raw secrets into prompts/logs.
  • Fail-closed --cdp-url loopback SSRF allowlist: Rejects non-loopback targets and cloud metadata addresses before connecting.
  • Isolated CDP world hydration: Injects LocalStorage in an isolated CDP execution world rather than polluting page globals.
  • Runnable 14/14 adversarial verification suite: Run python3 scripts/security_verify.py locally, and inspect our explicit “Not tested ≠ clean” threat boundaries in docs/security-report.md.

Try & Reproduce Locally

One-line setup (auto-wires Claude Code, Cursor, Antigravity, Codex, OpenCode):

curl -fsSL https://raw.githubusercontent.com/wasabihu/sessfork/main/install.sh | bash

Or clone and reproduce the exact token & security benchmarks locally (zero network, zero API keys):

git clone https://github.com/wasabihu/sessfork.git
cd sessfork
python3 scripts/bench_tokens.py
python3 scripts/security_verify.py

Would love feedback from anyone running multi-agent browser automation or local/small models over MCP — especially edge cases in CDP AXTree distillation, custom SPA modals, or trimming serde_json allocations on huge accessibility payloads!

Discussion & Feedback Join the discussion or share feedback on GitHub Discussions →