Once you wire up global MCP servers in agy, two practical headaches show up fast:
Heavy background resources spin up on every session start: Point mcp_config.json directly at chrome-devtools-mcp or docker run ... mcp-atlassian, and every agy session pops open a debug Chrome instance or spins up a Docker container—even if you only opened the CLI to tweak two lines of a Go unit test and never touch a browser or Jira. Open four or five terminal splits in parallel, and RAM usage and your container list blow up immediately.
A shared debug Chrome turns into tab soup: Even after consolidating Chrome into a single shared instance, three concurrent sessions calling new_page dump a dozen localhost, Swagger, and error tabs into the same window. You cannot tell which tab belongs to which session, and you hesitate to close any of them.
This post walks through the setup running on my machine: two zero-dependency Python stdio proxies that cut cold-start resource overhead to zero, paired with a 70-line RPC helper and a minimal Chrome MV3 extension that automatically files every tab opened by an AGY session into a tab group named after that session’s title.
1. Two Lazy-Loading Strategies for Heavy MCP Servers
First, an important distinction: Antigravity’s built-in Lazy Loading covered in Part 8 of the Field Guide is schema lazy loading—it saves prompt tokens, but the MCP server process itself still starts with the session. The proxies here implement process- and container-level lazy loading, eliminating RAM overhead and cold starts for debug Chrome instances and Docker containers.
My global ~/.gemini/config/mcp_config.json configures four everyday servers. context7 and memory are lightweight local Node processes that can start eagerly; the real resource hogs are chrome-devtools and jira-internal:
Both need lazy loading, but their bottlenecks differ, so each uses a different proxy pattern:
Server
Actual Resource Bottleneck
Proxy Strategy
chrome-devtools
chrome-devtools-mcp itself is light; the Chrome instance it attaches to is heavy
Transparent pass-through proxy: Starts chrome-devtools-mcp --browserUrl=... up front and passes handshakes and tools/list straight through; checks and launches the standalone debug Chrome on demand only when intercepting a tools/call
jira-internal
The entire server runs inside a Docker container—even answering tools/list requires docker run
Local-handshake proxy: Answers initialize, ping, tools/list, and notifications/* directly in Python; spawns the Docker container only on the first tools/call, transparently replaying the handshake
Start with a thin shell wrapper at ~/.gemini/bin/chrome-devtools-mcp.sh to keep the path stable and forward arguments cleanly:
1 2 3
#!/usr/bin/env bash set -euo pipefail exec python3 /home/user/.gemini/bin/chrome-devtools-mcp-lazy.py "$@"
The core logic lives in ~/.gemini/bin/chrome-devtools-mcp-lazy.py. Writing these 170 lines exposed four classic pitfalls, each guarded directly in code:
Bypass proxy environment variables when probing localhost: Dev machines commonly export HTTP_PROXY or ALL_PROXY. Probing http://127.0.0.1:9223/json/version via urllib.request can route through the proxy and return 502, tricking the script into repeatedly spawning Chrome. Using low-level http.client.HTTPConnection("127.0.0.1", 9223) ignores proxy env vars completely.
File lock to prevent concurrent duplicate launches: When two sessions trigger browser tools at the same instant, an unlocked launch races two Chrome instances onto the same --user-data-dir, crashing one of them. Locking <PROFILE_DIR>/.launch.lock via fcntl.flock (15-second timeout) and double-checking is_ready() after acquiring the lock prevents the race.
Detach Chrome from the CLI lifecycle with systemd-run --user --collect: Spawning Chrome as a direct child of the proxy means closing one terminal window can send SIGHUP to the process group and tear down Chrome for every other active session. Delegating startup to user-level systemd via systemd-run --user --unit=agy-debug-chrome --collect isolates its lifecycle, falling back to start_new_session=True when systemd is unavailable.
Always use a dedicated --user-data-dir: Never reuse your daily browser’s default profile, or Chrome will detect the running instance and silently ignore --remote-debugging-port.
if __name__ == "__main__": raise SystemExit(main())
Evolution note: The signal handler above includes raise SystemExit(128 + signum) so the proxy does not hang on the blocking sys.stdin.buffer.readline() call after receiving SIGTERM. If you share one debug Chrome across parallel terminals, continue to #5 Multi-Session Chrome Guardrails and the 6th Orange Status Color to see how this proxy evolves into a bidirectional cross-session guardrail backed by CDP targetId ownership.
Two extra CLI flags worth keeping enabled:
--backgroundNewPages: Prevents background tabs opened by the agent from stealing your desktop focus.
--categoryExtensions: Enables extension-management tools so you can reload local unpacked extensions directly inside the debug Chrome.
For Jira MCP, I run the ghcr.io/sooperset/mcp-atlassian image—pinned to an @sha256 digest and locked down with READ_ONLY_MODE=true and ENABLED_TOOLS=jira_get_issue,jira_search so the agent can never mutate live tickets.
The problem is that listing it in mcp_config.json makes agy run MCP discovery (initialize → notifications/initialized → tools/list) the moment a session starts, spinning up the container and keeping it alive until exit.
The fix is to handle the entire discovery phase locally inside the Python proxy:
Cache the client’s initialize.params (including protocolVersion and capabilities) and immediately return a locally constructed initialize response.
Serve pre-recorded JSON Schemas for jira_get_issue and jira_search on tools/list, and empty arrays on resources/list and prompts/list.
Only when a non-discovery request (such as tools/call) arrives does ensure_backend() start the Docker container, replay the saved initialize request under an internal ID (__agy_jira_lazy_init__), consume the backend’s response, and send notifications/initialized.
Once the handshake completes, a daemon thread (_pump_stdout) continuously forwards container stdout back to agy, and the main loop switches to raw byte-level pass-through without reparsing JSON.
On exit, the proxy closes container stdin and runs wait(5) → terminate() → kill(); paired with docker run --rm, no orphaned containers remain.
Core excerpt below (the full ~100-line static TOOLS schema is abbreviated—just run tools/list against the container once and paste the output):
@staticmethod def_pump_stdout(proc: subprocess.Popen[bytes]) -> None: assert proc.stdout isnotNone try: for line initer(proc.stdout.readline, b""): write_client(line) except OSError: pass
With this proxy in place, opening 10 code-only agy sessions leaves zero Jira containers in docker ps. When you actually look up a ticket, the first jira_get_issue takes about 1.5 seconds to spin up the container; every subsequent query in that session runs instantaneously over the live stdio pipe.
If you upgrade the MCP image and tool parameters change, update the TOOLS list in the proxy script to match. For a Jira integration exposing just two read-only query tools, the schema rarely changes, so maintenance cost is effectively zero.
4. Shared Chrome Across Sessions: Auto-Grouping Tabs by AGY Session Title
Once Chrome is consolidated onto a single instance on port 9223, the next problem is tab collisions across concurrent sessions.
Chrome’s chrome.tabGroups API is only exposed to extensions—CDP itself cannot create or assign tab groups. Breaking the workflow into three small pieces produces a surprisingly clean solution:
Fetch the current AGY session title (session-tab-url.py)
Install a 50-line JS MV3 extension in the debug Chrome (~/.gemini/chrome-tab-group-ext/)
Add a global Skill requiring the agent to wrap URLs before opening tabs (~/.gemini/config/skills/browser-tab-group/SKILL.md)
End-to-end interaction sequence:
sequenceDiagram
participant A as Antigravity Session
participant S as session-tab-url.py
participant LS as Local LS (GetConversation)
participant MCP as chrome-devtools MCP
participant EXT as MV3 Extension (group.html)
A->>S: --url "https://example.com"
S->>LS: POST /product.v1.ConversationService/GetConversation
LS-->>S: annotations.title (fallback: state.summary)
S-->>A: chrome-extension://<ext_id>/group.html?group=<title>&url=<target>
A->>MCP: new_page(url="chrome-extension://...")
MCP->>EXT: Open extension redirect page
EXT->>EXT: chrome.tabGroups.query(title) reuse or create & color
EXT->>EXT: Validate ^https?:// then chrome.tabs.update to target URL
1. Reading the Session Title and Building the Redirect URL (session-tab-url.py)
When agy runs a command, it injects ANTIGRAVITY_LS_ADDRESS, ANTIGRAVITY_CSRF_TOKEN, and ANTIGRAVITY_CONVERSATION_ID. Call the local Connect-RPC endpoint ConversationService/GetConversation, preferring annotations.title and falling back to state.summary:
#!/usr/bin/env python3 """Print the current Antigravity conversation title (or a tab-grouper redirect URL).""" import json, os, sys, urllib.parse, urllib.request
defget_session_title(): addr = os.environ.get("ANTIGRAVITY_LS_ADDRESS", "").strip() csrf = os.environ.get("ANTIGRAVITY_CSRF_TOKEN", "").strip() conv_id = os.environ.get("ANTIGRAVITY_CONVERSATION_ID", "").strip() ifnot (addr and csrf and conv_id): raise RuntimeError( "Missing Antigravity conversation env vars " "(ANTIGRAVITY_LS_ADDRESS / ANTIGRAVITY_CSRF_TOKEN / ANTIGRAVITY_CONVERSATION_ID)." ) req = urllib.request.Request( f"http://{addr}/product.v1.ConversationService/GetConversation", data=json.dumps({"conversationId": conv_id}).encode("utf-8"), headers={ "Content-Type": "application/json", "Connect-Protocol-Version": "1", "x-antigravity-csrf-token": csrf, }, method="POST", ) try: with urllib.request.urlopen(req, timeout=3) as resp: data = json.loads(resp.read().decode("utf-8")) except Exception as exc: raise RuntimeError( f"Failed to resolve conversation title via GetConversation ({exc}). " "If blocked by sandbox (e.g., HTTP 403 / connection refused), " "rerun this command outside the sandbox." ) from exc title = (data.get("annotations") or {}).get("title") or"" summary = (data.get("state") or {}).get("summary") or"" picked = title.strip() or summary.strip() ifnot picked: raise RuntimeError(f"Conversation {conv_id} has neither annotations.title nor state.summary.") return picked
Place the extension in ~/.gemini/chrome-tab-group-ext/, enable Developer Mode in the debug Chrome’s chrome://extensions, load it unpacked once, and save the generated extension ID into extension_id in the same directory.
If you want the same unpacked extension to keep an identical extension ID across multiple machines (so you do not have to copy extension_id on every host), pin the "key" field in manifest.json. See #4 Cross-Platform Backup and One-Click Bootstrap for how to generate it.
manifest.json requests only two minimal permissions:
1 2 3 4 5 6 7
{ "manifest_version":3, "name":"Antigravity Session Tab Grouper", "version":"1.0.0", "description":"Group tabs opened by Antigravity CLI sessions using the current conversation title.", "permissions":["tabs","tabGroups"] }
group.html serves as the redirect landing page with a single status element and an external script tag (MV3 disallows inline scripts):
group.js does four things: picks a deterministic color by hashing the group title, checks the current window for an existing group with that name, joins it or creates a new one, and redirects only to ^https?:// URLs (blocking crafted javascript: or file:// redirects):
if (/^https?:\/\//i.test(targetUrl)) { statusEl.textContent = `Grouped into "${groupName}", redirecting...`; await chrome.tabs.update(tab.id, { url: targetUrl }); } else { statusEl.textContent = `Grouped into "${groupName}".`; } }
run().catch((err) => { const statusEl = document.getElementById("status"); if (statusEl) statusEl.textContent = `Tab group error: ${err?.message || err}`; });
3. Enforcing Behavior and Edge Cases with a Global Skill (SKILL.md)
Having the script and extension on disk is not enough—the agent will not remember to invoke them on its own. Install a global Skill at ~/.gemini/config/skills/browser-tab-group/SKILL.md and encode the real-world edge cases directly in the rules:
--- name: browser-tab-group description: >- Use this skill whenever opening a new browser tab with the chrome-devtools MCP (new_page) or starting browser automation/debugging in Chrome. Ensures every tab opened by this Antigravity session is placed into a single Chrome tab group named after the current Antigravity conversation title. --- # Browser Session Tab Grouping 1. **Always wrap `new_page` URLs through the local tab-grouper helper**: python3 ~/.gemini/config/skills/browser-tab-group/scripts/session-tab-url.py --url "<target-url>" - If the terminal sandbox blocks `GetConversation`, rerun **only** that helper command outside the sandbox. - Never fall back to the workspace directory name or pass `<target-url>` directly to `new_page`.
2.**One tab group per conversation**: - First tab creates and names the group; subsequent tabs join the same group automatically. - Reuse an existing tab in this session's group via `navigate_page` when a new tab is unnecessary.
3.**Wait for redirect before interacting**: - Verify via `list_pages` or `take_snapshot` that the tab has left `group.html` before clicking or filling.
4.**Edge cases**: - Do not combine `chrome-extension://` URLs with `isolatedContext`; isolated browser contexts cannot run the local extension.
Three pitfalls from real usage deserve calling out explicitly:
Sandbox blocking localhost loopback: With the terminal sandbox enabled, local port connections are blocked by default, so session-tab-url.py fails to reach GetConversation. Make sure the error hint instructs the agent to rerun only that helper outside the sandbox—and never let the agent fall back to the workspace directory name, or three sessions in the same repository will pile back into one tab group.
Redirect race condition: When new_page returns, the tab may still be on group.html mid-chrome.tabs.update. Calling click or take_snapshot immediately hits the redirect stub instead of the target page, which is why Rule 3 requires verifying the URL has moved past group.html first.
isolatedContext incompatibility: Incognito/isolated browser contexts cannot load chrome-extension:// pages. When you explicitly need an unauthenticated verification session, pass the target URL directly.