6.5 KiB
Multi-Client / Multi-Agent Support
This document describes how multiple AI agents (or CLI users) safely share a
single cremotedaemon + Chrome instance.
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Agent 1 │ │ Agent 2 │ │ Agent N │
│ (LLM/CLI) │ │ (LLM/CLI) │ │ (LLM/CLI) │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ stdio │ stdio │ stdio (or HTTP CLI)
┌──────┴───────┐ ┌──────┴───────┐ ┌──────┴───────┐
│ cremote-mcp │ │ cremote-mcp │ │ cremote-mcp │ ← one MCP process
│ (process) │ │ (process) │ │ (process) │ per agent; each
│ currentTab, │ │ currentTab, │ │ currentTab, │ holds its OWN
│ iframeMode │ │ iframeMode │ │ iframeMode │ session state
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ HTTP (always sends an explicit tab id)
└──────────────────┼──────────────────┘
│
┌─────────────┴─────────────┐
│ cremotedaemon │ ← ONE shared daemon
│ (stateless re: current │ (no current tab, no history)
│ tab; per-tab maps keyed │
│ by Chrome TargetID) │
└─────────────┬─────────────┘
│ CDP / WebSocket
┌─────────────┴─────────────┐
│ Chrome / Chromium │
│ (all tabs accessible) │
└───────────────────────────┘
How isolation is achieved
There is no session layer and no daemon-side "current tab". Instead, isolation comes from two properties:
-
One
cremote-mcpprocess per agent. Each agent's MCP server is a separate process with its own in-memorycurrentTab,tabHistory, andiframeMode. There is no shared process state between agents. (The MCP server is served over stdio; it does not run an HTTP listener.) -
The daemon requires an explicit tab id on every call and keys all per-tab state (cached page, iframe context, console logs) by the globally-unique Chrome
TargetID. Because each agent opens its own tabs and always passes the tab id it received, two agents never address the same map entry.
What was removed and why
Earlier revisions of this guide described an HTTP transport with
Mcp-Session-Id headers and a daemon-tracked "current tab" / tab history.
Neither existed in the code: the MCP server only ever spoke stdio, and a
process-global currentTab is not safe to share across concurrent clients
(two agents that omit the tab id would silently operate on whichever tab was
touched last). The current-tab fallback was therefore removed entirely.
Concretely, in daemon/daemon.go:
Daemon.currentTabandDaemon.tabHistoryfields: removed.getTabID()(empty → current tab fallback) andupdateTabHistory(): removed.- Every operation (
getTab,closeTab,switchToIframe,switchToMain,getConsoleLogs, and all 20+ command handlers) now returnstab id is requiredwhen the tab id is empty. - The single mutex was split into
stateMu, which guards only thetabs/iframePages/consoleLogsmaps. Long Chrome DevTools Protocol calls (notablyswitchToIframe's element/frame waits, andopenTab's page creation) now run lock-free, so one agent switching iframes no longer blocks another agent clicking on a different tab.
Implications for callers
MCP clients
No change required. Each agent's MCP process already tracked its own
currentTab and always sent an explicit tab id to the daemon, so the
multi-agent workflow continues to work. If an agent's MCP process has not yet
opened/navigated a tab, tools that need a tab will now return
tab id is required; call web_manage_tabs (open or switch) first.
CLI clients
You must now pass --tab on every command that operates on a tab. The
convenience of omitting --tab is gone. Capture the id from open-tab:
TAB=$(cremote open-tab)
cremote load-url --tab="$TAB" --url="https://example.com"
cremote click-element --tab="$TAB" --selector="a.button"
cremote close-tab --tab="$TAB"
list-tabs
The * "current tab" marker and history-based ordering are gone. Tabs are
listed by id. /status no longer returns current_tab or tab_history;
clients that read those keys get empty values (graceful).
Remaining concurrency notes / future hardening
- No tab ownership enforcement. Any client can address any tab by id. This
is fine for trusted agents but means a fat-fingered id could touch another
agent's tab. Optional
tabOwnerstracking + a--strict-ownershipflag is a straightforward follow-up. - No per-tab lock. Two concurrent operations against the same tab are the caller's responsibility (each MCP process is request/response, so this does not arise naturally). A per-tab mutex keyed by TargetID can be added if needed.
- Tab lifecycle. Tabs opened by an MCP process are not auto-closed when
that process exits; agents should close their tabs. A
release-sessioncleanup hook is a future improvement.
Verification
daemon/daemon_test.gocovers the tab-required contract and concurrentconsoleLogsaccess; run withgo test -race ./daemon/....TestMultiAgentIsolationis a Chrome-backed integration test (several agents open distinct tabs in parallel and assert no cross-agent content leak). Run it with:It requires Chrome reachable on port 9222 viaCREMOTE_INTEGRATION=1 go test -race -run TestMultiAgentIsolation ./daemon/...http://localhost:9222/json/version(note: some environments resolvelocalhostto IPv6::1while Chrome listens on IPv4127.0.0.1; ensurelocalhostresolves to IPv4 for the discovery check to pass).