How emprider/airbridge works
1. This repo is a protocol bridge, not a model host.
Its purpose is to let MCP-compatible AI tools talk to web-based LLM UIs through real browser automation. The two key external boundaries are:
- MCP clients on stdin/stdout
- A browser-driven target service such as Gemini in Playwright
2. main.py is the entrypoint and mode switch.
It runs either as:
- a standalone HTTP server when --server is used, or
- a thin MCP client/proxy otherwise.
This split is the core architectural decision in the repo.
3. The MCP client is intentionally thin.
mcp_manager/mcp_client.py handles JSON-RPC 2.0 over stdin/stdout, auto-starts the server if needed, registers a unique client ID, and forwards tool calls over localhost HTTP. This keeps IDE subprocess integration separate from the heavy browser work.
4. The HTTP server is the real control plane.
mcp_manager/http_server.py exposes FastAPI endpoints for:
- health/config/task discovery
- client registration and unregistering
- one-shot queries
- chat session lifecycle
- graceful shutdown and stats
This is the main orchestration surface once requests leave MCP transport.
5. Configuration drives routing from “task” to adapter.
mcp_manager/config.json defines named tasks, each with:
- adapter name
- target URL
- available models
- login settings
- CSS selectors for browser automation
mcp_manager/adapters/adapter_factory.py reads that mapping and instantiates the right adapter class by registry name.
6. Adapters are the per-target automation boundary.
The adapter layer is where site-specific behavior lives. The repo includes a generic adapter base and a Gemini-oriented implementation pattern. Adapters are responsible for:
- opening the target page
- selecting the model
- submitting prompts
- waiting for completion
- extracting the response text
Crucially, adapters do not own browser lifecycle; they only operate on the page/context given to them.
7. Browser concurrency is handled by a Playwright context pool.
mcp_manager/browser_pool.py manages a bounded pool of browser contexts rather than spawning a full browser per request. The pool supports:
- lazy or eager spawning
- idle context cleanup
- isolation via separate contexts and profiles
- performance controls like image/font disabling
mcp_manager/browser.py contains browser/profile discovery and profile management details.
8. One-shot prompts and multi-turn sessions are different subsystems.
mcp_manager/session_manager.py owns chat sessions, where each session gets a dedicated browser slot and per-session lock.
The system distinguishes:
- one-shot query flow: acquire a pooled context, run adapter process, release it
- session flow: reserve a context, keep page state alive, send multiple turns, then explicitly release it
9. Authentication is treated as a first-class browser concern.
mcp_manager/login_handler.py handles manual login flows when a site requires auth. The repo uses a persistent “golden” profile so future browser contexts inherit cookies. That means login happens once, then gets copied into pooled contexts for reuse.
10. Lifecycle and process coordination are managed separately from request handling.
mcp_manager/server_manager.py coordinates server startup/shutdown and PID-file-based process detection. This is what allows the MCP client to start the HTTP server on demand and avoid duplicate server instances.
11. There is a clear separation between transport, orchestration, and automation.
- Transport: MCP JSON-RPC and HTTP API
- Orchestration: server, session, and client managers
- Automation: browser pool + adapters + login handling
That separation is what makes the repo extensible to new LLM sites without rewriting the client/server plumbing.
12. mcp_manager/server.py appears to be a legacy or alternative MCP stdio server path.
The README describes the HTTP-backed client/server design as the main architecture, while server.py suggests an older direct stdio implementation that remains in the tree for compatibility or reference.
13. The remaining files are support and validation.
- utils.py contains shared helpers used by browser automation
- test_dummy.py and test_gemini.py are lightweight validation hooks
- sample-mode-for-roo-code and sample-skill-file are integration examples rather than core runtime components
14. What an architecture diagram should emphasize:
The main flow is: AI tool → MCP client → HTTP server → adapter factory → browser pool/session manager → Playwright browser → target web LLM UI → back up the stack.
The main boundaries are protocol transport, task-to-adapter routing, pooled browser execution, and persistent session/login state.
Main entry points: http_server.py HTTP server · browser_pool.py Browser pool · generic_adapter.py Generic adapter · mcp_client.py MCP client
Components 16
Transport
MCP stdio and HTTP API boundaries
- MCP client · JSON-RPC over stdin/stdout that forwards tool calls to the local server
mcp_manager/mcp_client.py - HTTP server · FastAPI orchestration surface for health, tasks, sessions, and shutdown
mcp_manager/http_server.py - Legacy server · Alternative direct MCP server path kept for compatibility or reference
mcp_manager/server.py
Orchestration
Startup, routing, sessions, and process coordination
- Main entry · Chooses between standalone server mode and thin MCP client mode
main.py - Server manager · Starts, stops, and detects the HTTP server process
mcp_manager/server_manager.py - Session manager · Owns persistent multi-turn sessions with dedicated browser slots and locks
mcp_manager/session_manager.py - Task config · Named tasks map to adapters, targets, models, login settings, and selectors
config.json
Automation
Playwright contexts, adapters, and login state
- Adapter factory · Creates the right adapter implementation for a configured task
mcp_manager/adapters/adapter_factory.py - Generic adapter · Base pattern for opening the target page, prompting, waiting, and extracting replies
mcp_manager/adapters/generic_adapter.py - Browser pool · Manages bounded Playwright contexts with reuse, cleanup, and isolation
mcp_manager/browser_pool.py - Browser mgmt · Browser and profile discovery plus persistent profile handling
mcp_manager/browser.py - Login handler · Handles manual site login and seeds the persistent golden profile
mcp_manager/login_handler.py - Playwright · Browser automation runtime used by pooled contexts
- Web LLM UI · Browser-based model interface such as Gemini that receives prompts and returns completions
Connections 19
- Main entry → MCP client: proxy mode · Runs the thin MCP client path when not starting the server
- Main entry → HTTP server: server mode · Starts the standalone HTTP server when requested
- MCP client → Server manager: start if needed · Ensures the HTTP server is running before forwarding requests
- MCP client → HTTP server: forward tool calls · Sends JSON-RPC tool requests over localhost HTTP
- HTTP server → Task config: load tasks · Reads task definitions and automation settings
- HTTP server → Adapter factory: resolve adapter · Routes each request to the configured adapter implementation
- HTTP server → Session manager: manage sessions · Creates, reuses, and releases persistent chat sessions
- HTTP server → Browser pool: one-shot contexts · Acquires pooled browser contexts for single queries
- Session manager → Browser pool: reserve context · Pins a browser slot to a session for multi-turn state
- Adapter factory → Generic adapter: instantiate · Constructs the site-specific adapter from the registry mapping
- Generic adapter → Browser pool: operate page · Uses a provided browser context without owning lifecycle
- Browser pool → Playwright: create contexts · Spawns and manages Playwright browser contexts
- Browser pool → Browser mgmt: profile control · Relies on browser/profile discovery and persistent profile setup
- Browser pool → Login handler: auth reuse · Copies authenticated state from the golden profile into pooled contexts
- Login handler → Web LLM UI: log in · Performs manual browser login against the target web UI
- Generic adapter → Web LLM UI: submit prompt · Sends prompts and extracts completion text from the site UI
- Browser mgmt → Login handler: seed profile · Maintains the persistent profile that stores login state
- Legacy server → MCP client: compatibility · Represents the older direct stdio server path kept alongside the HTTP-backed design
- Generic adapter → Helpers: shared helpers · Uses common helper routines during browser automation