Harness Bridge
# Harness Bridge
[](https://github.com/sukumar1210/harness-bridge/actions/workflows/ci.yml)
[](https://m8ven.ai/mcp/sukumar1210-harness-bridge-13ucsb?s=readme)
[](https://github.com/sukumar1210/harness-bridge/discussions/16)
[](https://opensource.org/licenses/MIT)
**Harness Bridge** is a lightweight, harness-agnostic inter-agent proxy and Model Context Protocol (MCP) server for AI coding agents. It enables CLI-based harnesses (such as **Claude Code** and **Antigravity CLI**) to interoperate seamlessly, dispatching tasks, executing code in isolated sandboxes, and collaborating across distinct machines and subscription accounts.
---
## Harness Bridge — Proposed Final Architecture
**One central broker. Local MCP adapters for agents. Lightweight native workers for execution.**
*Recommended Architecture • Distributed-Ready*
```mermaid
flowchart TD
subgraph MachineA["Machine A — Orchestrator"]
ClaudeA["Claude Code CLI"]
MCPAdapterA["Local MCP Adapter\n(harness-bridge adapter)"]
ClaudeA -->|"MCP over stdio"| MCPAdapterA
end
subgraph CentralBroker["Central Infrastructure — Docker (Zero Host Mounts)"]
MCPServer["MCP Server\n(/sse · /mcp)"]
RelayBus["Relay Bus\n(SQLite WAL · Task Queue)"]
WorkerGW["Worker HTTP/SSE Gateway\n(/api/v1/workers/*)"]
Health["Health Probe\n(/health)"]
MCPServer <--> RelayBus
RelayBus <--> WorkerGW
end
subgraph MachineB["Machine B — Execution"]
WorkerB["Native Worker Runtime\n(harness-bridge worker run / service)"]
HarnessB["Antigravity CLI (agy)"]
StorageB["Local Filesystem & Auth\n(/srv/sources · /srv/data · ~/.gemini)"]
WorkerB -->|"Native subprocess"| HarnessB
HarnessB -->|"Direct access"| StorageB
end
subgraph MachineC["Machine C — Execution (Optional)"]
WorkerC["Native Worker Runtime\n(harness-bridge worker run / service)"]
HarnessC["Claude Code CLI / Other"]
WorkerC -->|"Native subprocess"| HarnessC
end
MCPAdapterA -->|"MCP over HTTP/SSE"| MCPServer
WorkerGW -->|"Server-Sent Events (Task Push)"| WorkerB
WorkerB -->|"HTTP POST (Acks / Results / Heartbeats)"| WorkerGW
WorkerGW -.->|"Server-Sent Events"| WorkerC
WorkerC -.->|"HTTP POST"| WorkerGW
```
### 1. Component Responsibilities
| Component | Runs Where | Responsibility |
| --- | --- | --- |
| **MCP Adapter** | Agent machine | Exposes broker tools to local AI agents over stdio |
| **MCP Server** | Central Docker Broker | Exposes standard MCP tools over SSE and streamable HTTP (`/sse`, `/mcp`) |
| **Relay Bus** | Central Docker Broker | Manages task queue, leases, sessions, and state machines |
| **Worker Gateway** | Central Docker Broker | Real-time SSE task delivery (`/api/v1/workers/events`) and HTTP result ingestion |
| **Native Worker** | Execution machine | Connects outward via SSE; executes tasks with local tools |
| **Harness CLI** | Execution machine | Runs `agy`, `claude`, etc. natively on the host |
### 2. Communication Protocols
| Connection | Protocol | Characteristics |
| --- | --- | --- |
| **Claude / Agent → MCP Adapter** | MCP over `stdio` | Standard MCP JSON-RPC protocol; agent sees zero network complexity |
| **MCP Adapter → Broker** | MCP over HTTP/SSE | Remote tool routing over network |
| **Broker → Worker** | Server-Sent Events (SSE) | Event-driven push; worker holds open connection at 0% idle CPU |
| **Worker → Broker** | HTTP POST | Task acknowledgements, progress heartbeats, and result payloads |
| **Worker → Harness CLI** | Native subprocess execution | Direct host execution with access to local files, tools, and auth |
> **Note:** The worker never needs to speak MCP. Agents communicate through MCP; machines communicate through the relay protocol; execution happens locally.
### 3. Installation Experience
#### Central Broker
Run the decoupled broker with zero host volume mounts:
```bash
./install.sh --docker
# or manually via Docker:
docker run -d \
--name harness-bridge \
--restart unless-stopped \
-p 8000:8000 \
-v harness-bridge-data:/home/bridge/.harness-bridge \
sukumar1210/harness-bridge:latest
```
#### Orchestrator Machine (Local Agent MCP Setup)
```bash
harness-bridge setup --force
```
#### Execution Machine — Foreground
```bash
harness-bridge worker run --server http://<broker-ip>:8000
```
#### Execution Machine — Persistent OS Service (Optional)
Install and manage as a native user service (`systemd --user` on Linux, `launchd` on macOS):
```bash
# Install and auto-start user service
harness-bridge worker service install --server http://<broker-ip>:8000
# Service lifecycle commands
harness-bridge worker service status
harness-bridge worker service stop
harness-bridge worker service start
harness-bridge worker service restart
harness-bridge worker service uninstall
```
### 4. Architectural Invariants
- **01: No Docker host mounts**: The broker never accesses execution-machine filesystems. It remains 100% portable and decoupled from host directories, disk structures, and UIDs.
- **02: No mandatory OS services**: Workers can run interactively in the foreground (`harness-bridge worker run`) or as managed user services (`harness-bridge worker service install`).
- **03: No agent polling**: SSE event-driven task push eliminates polling latency, CPU waste, and agent context exhaustion.
- **04: No unnecessary MCP servers**: Only agent-facing machines require MCP adapters. Execution machines only run the lightweight native worker daemon.
- **05: Native execution**: Workers have direct access to local host tools, CLIs, local repositories (`/srv/sources`), datasets (`/srv/data`), and user credentials (`~/.gemini`).
- **06: Independent scaling**: Scale execution machines horizontally without modifying the broker.
### 5. Implementation Details
- **Worker Authentication & Identity**: Automatic hardware- and PID-derived machine identity (`worker_id`) with optional bearer tokens (`HARNESS_BRIDGE_TOKEN`).
- **Sliding Leases & Heartbeats**: 45-second sliding task leases with automatic heartbeats, reconnection recovery, and graceful re-queuing on worker disconnection.
- **Task Acknowledgement & Idempotence**: Explicit task state machine transitions (`pending` → `leased` → `acknowledged` → `running` → `completed` / `failed`).
- **Durable State**: SQLite WAL-backed relay bus retains task status and lease records across network interruptions and container restarts.
- **Zero Exposed Host Credentials**: Host credentials and OAuth tokens remain strictly local on the execution machine.
### Final Design Decision: 1 Broker + N Adapters + N Native Workers
* **1 Central Broker**: Handles state, queueing, and MCP routing with zero host mounts.
* **N MCP Adapters**: Provides stdio MCP interfaces to local AI agents.
* **N Native Workers**: Executes tasks natively with local tools and credentials.
---
---
## Features
- **Standard Model Context Protocol (MCP) Server**: Exposes standard tools (`bridge_list_harnesses`, `bridge_dispatch_task`, `bridge_apply_diff`, `bridge_get_session`, `bridge_close_session`) that any MCP-compliant agent can invoke directly.
- **Dedicated Native Drivers**: Built-in, headless drivers for Claude Code (`claude`) and Antigravity CLI (`agy`) with conversational continuity across turns via native session resumption flags (`--resume` / `--conversation`).
- **Workspace Sandboxing via Git Worktrees**: Ephemeral git worktrees (`.worktrees/<session_id>`) prevent concurrent file clobbering. Review generated diffs safely before applying them with `bridge_apply_diff`.
- **Kernel Buffer & Protocol Deadlock Prevention**: Asynchronous execution via `proc.communicate()` wrapped with timeouts eliminates 64KB Linux pipe buffer deadlocks. All server logs route strictly to `stderr` to preserve clean JSON-RPC framing.
- **Distributed Loop Protection**: Injects `HARNESS_BRIDGE_TRACE_ID` and `HARNESS_BRIDGE_HOP_COUNT` into child processes to prevent recursive agent fork bombs.
- **Self-Updating**: Built-in `harness-bridge update` command syncs with GitHub Releases and updates in-place via pre-compiled `.whl` distribution assets.
---
## Quick Start & Installation
### One-Shot Installer (Recommended)
Bootstrap Harness Bridge in a single command. The installer automatically detects your environment, offers a choice between **Docker** and **Local CLI**, and registers the MCP server in your installed coding harnesses (Claude Code, Antigravity):
#### Linux & macOS:
```bash
curl -fsSL https://raw.githubusercontent.com/sukumar1210/harness-bridge/main/install.sh | bash
```
#### Windows (PowerShell):
```powershell
irm https://raw.githubusercontent.com/sukumar1210/harness-bridge/main/install.ps1 | iex
```
*In interactive terminals, the installer prompts between Docker (Recommended) and Local installation. In automated or CI/CD environments, it auto-detects the runtime (or accepts `--docker` / `--local` / `-y` flags).*
---
### Manual Installation Options
If you prefer installing manually without running scripts:
#### Option 1: Docker (Central Broker — Zero Host Volume Mounts)
Pull and run the pre-built multi-architecture broker container from Docker Hub with zero host mounts:
```bash
docker run -d \
--name harness-bridge \
--restart unless-stopped \
-p 8000:8000 \
-v harness-bridge-data:/home/bridge/.harness-bridge \
sukumar1210/harness-bridge:latest
# Connect your agent harnesses to the broker
claude mcp add --transport sse -s user harness-bridge http://localhost:8000/sse
agy mcp add harness-bridge http://localhost:8000/sse
# Start the native worker on your execution machine to run tasks
harness-bridge worker run --server http://localhost:8000
```
*The central broker manages task leases, state, and queues without mounting host filesystems. Native workers connect outward via SSE and execute tasks with local tools.*
> See the [Docker Guide](docs/docker.md) for custom port mappings, Docker Compose, and production deployment options.
#### Option 2: Local Host CLI (`pip` / `venv`)
Install the CLI into your user environment:
```bash
# Install via pip
pip install harness-bridge
# Register into Claude Code and Antigravity (uses on-demand stdio)
harness-bridge setup
```
#### Option 3: From Source (`uv`)
Clone the repository for local development:
```bash
git clone https://github.com/sukumar1210/harness-bridge.git
cd harness-bridge
uv sync
# Register local editable build
uv run harness-bridge setup
```
---
### Re-running Setup
If you reinstall Claude Code, update your Antigravity configuration, or switch between Docker and local runtimes, re-run setup at any time to repair harness registrations:
```bash
./setup.sh
# or on Windows:
.\setup.ps1
# or via CLI:
harness-bridge setup
```
---
### Multi-Device & Network Access
By default, local CLI installations run on-demand via standard MCP `stdio` (zero open ports, zero idle RAM). If you want other devices across your local network (LAN) to connect to Harness Bridge:
* **Via Docker**: Run the container with `-p 8000:8000` (exposed by default in Docker mode). Other devices on the LAN can connect to `http://<HOST-IP>:8000/sse`.
* **Via Local Host CLI**: Launch the server explicitly in network mode:
```bash
harness-bridge serve --transport unified --host 0.0.0.0 --port 8000
```
---
### Manual Registration by Harness
Harness Bridge exposes a standard Model Context Protocol (MCP) server over standard I/O (`stdio`). You can also register it manually in any MCP-compliant harness or IDE:
#### 1. Claude Code
Register Harness Bridge directly using the `claude` CLI:
```bash
claude mcp add harness-bridge -- harness-bridge serve
```
Alternatively, add it directly to your project or user configuration (`~/.claude.json`):
```json
{
"mcpServers": {
"harness-bridge": {
"command": "harness-bridge",
"args": ["serve"]
}
}
}
```
#### 2. Antigravity CLI (`agy`)
Register Harness Bridge using the `agy` CLI:
```bash
agy mcp add harness-bridge harness-bridge serve
```
Or configure it in your Antigravity MCP settings (`~/.gemini/antigravity-cli/mcp_config.json`):
```json
{
"mcpServers": {
"harness-bridge": {
"command": "harness-bridge",
"args": ["serve"]
}
}
}
```
#### 3. Cursor
In Cursor:
1. Navigate to **Cursor Settings** > **Features** > **MCP Servers**.
2. Click **+ Add New MCP Server**.
3. Fill in:
- **Name**: `harness-bridge`
- **Type**: `command`
- **Command**: `harness-bridge serve` *(or `~/.local/bin/harness-bridge serve` if not in global PATH)*
#### 4. Windsurf (Codeium Cascade)
Add the server configuration to `~/.codeium/windsurf/mcp_config.json`:
```json
{
"mcpServers": {
"harness-bridge": {
"command": "harness-bridge",
"args": ["serve"]
}
}
}
```
#### 5. Claude Desktop
Add to your `claude_desktop_config.json` (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS or `%APPDATA%\Claude\claude_desktop_config.json` on Windows):
```json
{
"mcpServers": {
"harness-bridge": {
"command": "harness-bridge",
"args": ["serve"]
}
}
}
```
#### 6. Generic MCP Clients / Zed / Goose
Any client supporting JSON-RPC stdio transport can connect to Harness Bridge:
* **Executable**: `harness-bridge` (or `$HOME/.local/bin/harness-bridge`)
* **Arguments**: `["serve"]`
* **Transport**: `stdio`
---
## CLI Usage
```bash
# List available harnesses on system PATH
harness-bridge list
# Check current version
harness-bridge version
# Check for updates from GitHub Releases
harness-bridge update --check
# Self-update to the latest release
harness-bridge update
# Run a one-shot task directly
harness-bridge run --target agy "Inspect README.md and explain the architecture"
# Start the MCP server manually
harness-bridge serve
# Start native worker daemon in foreground
harness-bridge worker run --server http://localhost:8000
# Install and manage persistent background worker service (systemd/launchd)
harness-bridge worker service install --server http://localhost:8000
harness-bridge worker service status
harness-bridge worker service stop
harness-bridge worker service start
# Run local MCP adapter proxying stdio to remote broker over SSE
harness-bridge adapter --server http://localhost:8000
```
---
## Architecture & System Internals (For Developers)
### Subdirectories & System Boundaries
- [Python Subsystem (`harness_bridge`)](./harness_bridge/README.md): Core implementation including CLI, drivers, session management, workspace sandboxing, and FastMCP server.
- [CLI (`harness_bridge/cli`)](./harness_bridge/cli/README.md): Typer/Rich command-line interface and MCP stdio server launcher.
- [Core (`harness_bridge/core`)](./harness_bridge/core/README.md): Domain exceptions, schemas, async process runner, harness configuration, and self-updater.
- [Drivers (`harness_bridge/drivers`)](./harness_bridge/drivers/README.md): Headless execution adapters and registry for Claude Code and Antigravity CLI.
- [Server (`harness_bridge/server`)](./harness_bridge/server/README.md): FastMCP stdio server exposing JSON-RPC tools for agent discovery and dispatch.
- [Session (`harness_bridge/session`)](./harness_bridge/session/README.md): Multi-turn conversational session lifecycle, tracing, and hop limit circuit breakers.
- [Workspace (`harness_bridge/workspace`)](./harness_bridge/workspace/README.md): Ephemeral git worktree sandboxing, diff extraction, and patch application.
- [Platform Scripts (`scripts`)](./scripts/README.md): Zero-dependency installation scripts (`install.sh`, `install.ps1`) and commit validation tooling.
- [Technical Design Specifications (`docs/designs`)](./docs/designs/SITEMAP.md): Canonical architectural RFCs and feature milestone specifications.
### Architectural Invariants
- **Stdio Transport Protocol Purity**: During `harness-bridge serve`, standard output (`stdout`) is strictly reserved for JSON-RPC 2.0 frames. All diagnostics, progress spinners, and log messages route strictly to `stderr`.
- **Subprocess Pipe Deadlock Immunity**: Cross-platform process execution in `run_command_safe` binds stdin to `DEVNULL` and reads output via `proc.communicate()`, eliminating 64KB OS pipe deadlocks.
- **Process Group Termination**: Child subprocesses are spawned in detached process groups (`process_group=0` on POSIX) and terminated recursively with `SIGTERM`/`SIGKILL` escalation on timeout.
- **Workspace Sandboxing Integrity**: Tasks executed under `worktree` isolation operate strictly within ephemeral `.worktrees/{session_id}` directories and dedicated `bridge/session-{session_id}` branches, never modifying the primary working tree until explicitly merged via `bridge_apply_diff`.
- **Distributed Delegation Recursion Ceiling**: Inter-agent delegation propagates `HARNESS_BRIDGE_TRACE_ID` and increments `HARNESS_BRIDGE_HOP_COUNT`, raising `MaxHopsExceededError` if recursion depth reaches `max_hops` (default: 10).
### System Side Effects
- **Child Subprocess Execution**: Spawns headless external AI coding harness CLIs (`claude`, `agy`) and git processes.
- **Repository Worktree & Branch Mutation**: Creates and removes `.worktrees/{session_id}` directories and mutates local git branches (`bridge/session-*`).
- **Harness MCP Configuration Writes**: Reads and updates configuration files across user directories (`~/.claude.json`, `~/.gemini/antigravity-cli/mcp_config.json`, `~/.gemini/config/mcp_config.json`).
- **Network Egress**: Issues HTTPS requests to `api.github.com` for release checks and updates, downloading `.whl` assets when upgrading.
### Development Verification
- Run tests: `uv run pytest -v tests/`
- Run lint & formatting: `uv run ruff check .` and `uv run ruff format .`
---
## Contributing
Contributions, issues, and feature requests are welcome!
- Vote on upcoming roadmap capabilities or propose new ideas in our [Feature Voting & Roadmap Hub](https://github.com/sukumar1210/harness-bridge/discussions/16) or browse the [Live Ideas Leaderboard](https://github.com/sukumar1210/harness-bridge/discussions/categories/ideas?discussions_q=is:open+category:Ideas+%22[Idea]%22+sort:top).
- See [CONTRIBUTING.md](CONTRIBUTING.md) for local development setup, git hooks (`pre-commit`), testing guidelines, and PR workflow.
- Please review our [Code of Conduct](CODE_OF_CONDUCT.md).
- To report security concerns, refer to [SECURITY.md](SECURITY.md).
---
## License
MIT © [Sukumar Rastogi](https://github.com/sukumar1210)
TDQS
Scored across 6 tools
Most tools target clearly distinct operations (list harnesses vs. dispatch task vs. apply diff). The main ambiguity is between bridge_cancel_session and bridge_close_session, which both terminate sessions; descriptions differentiate them (subprocess termination vs. worktree cleanup) but an agent could still misselect. The dispatch description's embedded workflow references to apply_diff and close_session help tie the set together.
All six tools use a uniform bridge_ prefix followed by a verb_noun pattern (list_harnesses, dispatch_task, cancel_session, apply_diff, get_session, close_session). No mixed conventions or stylistic deviations.
Six tools is tightly scoped to the dispatch-and-manage-session domain, with each tool covering a distinct lifecycle step. Nothing feels redundant or missing at this size.
The surface covers the full dispatch lifecycle: discover harnesses, dispatch (sync or detached), inspect output/diff, apply results, cancel, and clean up. The one notable gap is the lack of a list/inspect-active-sessions tool, so an agent that loses a session_id from a detached dispatch has no recovery path.