Skip to main content
Glama
README.md
# cli-orchestrator-mcp

[![CI](https://github.com/cancakmk/cli-orchestrator-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/cancakmk/cli-orchestrator-mcp/actions/workflows/ci.yml)
[![Version](https://img.shields.io/badge/Version-3.1.0-blue.svg)](package.json)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-339933.svg)](https://nodejs.org/)
[![Dependencies](https://img.shields.io/badge/Dependencies-0-brightgreen.svg)](#)
[![Protocol](https://img.shields.io/badge/Protocol-MCP%20(stdio)-purple.svg)](https://modelcontextprotocol.io/)
[![Platforms](https://img.shields.io/badge/Platforms-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey.svg)](#)

**Let ANY MCP-compatible AI IDE act as the Lead, and orchestrate MULTIPLE local AI CLI coding agents in parallel.**

`cli-orchestrator-mcp` is a **vendor-neutral, zero-dependency, asynchronous task-based MCP server** with a pluggable adapter architecture. Any IDE (**Antigravity, Claude Code, Cursor, VS Code, Windsurf, Cline / Roo Code, Zed**) can simultaneously dispatch tasks across **7 major local CLI agents** (**OpenCode, Antigravity CLI, Claude Code, Gemini CLI, OpenAI Codex, Cursor Agent CLI, and Aider**) with automatic `git worktree` isolation and stateful `session_id` continuation.

[Architecture](#architecture-hub-and-spoke-multi-ide-control) • [Supported CLIs](#supported-cli-workers-7-adapters) • [Benchmarks](#benchmarks-direct-cli-vs-cli-orchestrator-mcp) • [Tools](#mcp-tool-reference) • [Quick Start](#quick-start-zero-clone-via-npx) • [Lead Skill](#lead-orchestration-skill-optional)

---

## Architecture (Hub-and-Spoke Multi-IDE Control)

```mermaid
flowchart LR
    Lead["Any Lead IDE\n(Antigravity / Cursor / Claude Code / VS Code / Windsurf)"]
    MCP["cli-orchestrator-mcp\n(Async Task Registry + Git Worktree Manager)"]
    OC["OpenCode CLI\n(warm service daemon)"]
    AGY["Antigravity CLI (agy)\n(isolated worktree)"]
    CC["Claude Code CLI\n(isolated worktree)"]
    OTH["Gemini / Codex / Cursor / Aider\n(isolated worktree)"]

    Lead <-->|"JSON-RPC 2.0 (stdio)\n~25 ms async dispatch"| MCP
    MCP --> OC
    MCP --> AGY
    MCP --> CC
    MCP --> OTH
```

- **1 Lead → N Different Workers:** Combine subscriptions on one machine (e.g., fast UI/boilerplate on one CLI, deep architecture on another, independent code review on a third) in a single parallel wave.
- **Universal `git worktree` Isolation:** Providers with native worktree flags use them directly; for all other CLIs, the MCP server automatically creates and manages isolated git worktrees so concurrent edits never collide.
- **100% Vendor-Neutral:** Pure `worker_*` tool surface with zero hardcoded providers or external npm dependencies.

---

## Supported CLI Workers (7 Adapters)

Call `worker_list_providers` to auto-detect which CLIs are installed on your machine:

| Provider ID | CLI Tool | Status | Session Resume | Model List | Worktree Isolation | Env Override |
| :--- | :--- | :---: | :---: | :---: | :---: | :--- |
| `opencode` | **OpenCode CLI** (`opencode`) | Live Verified | `--session` | `opencode models` | Native `--worktree` | `OPENCODE_BIN` |
| `antigravity` | **Antigravity CLI** (`agy`) | Live Verified | `--conversation` | `agy models` | Auto git worktree | `AGY_BIN` |
| `claude-code` | **Claude Code CLI** (`claude`) | CLI Flags Verified | `--resume` | Hint/alias | Auto git worktree | `CLAUDE_BIN` |
| `gemini-cli` | **Gemini CLI** (`gemini`) | CLI Flags Verified | `--resume` | Hint/alias | Auto git worktree | `GEMINI_BIN` |
| `codex` | **OpenAI Codex CLI** (`codex`) | Beta *(PRs welcome)* | Thread ID | Hint/alias | Auto git worktree | `CODEX_BIN` |
| `cursor` | **Cursor Agent CLI** (`cursor-agent` / `agent`) | Beta *(PRs welcome)* | `--resume` | Hint/alias | Auto git worktree | `CURSOR_BIN` |
| `aider` | **Aider CLI** (`aider`) | Beta *(PRs welcome)* | — | Hint/alias | Auto git worktree | `AIDER_BIN` |

---

## Benchmarks: Direct CLI vs `cli-orchestrator-mcp`

Measured live using `npm run bench` ([`benchmarks/run.mjs`](benchmarks/run.mjs) • raw data in [`benchmarks/latest-results.json`](benchmarks/latest-results.json)).

### Test Environment
- **Platform:** Windows 11 (`win32 x64`) • **Node.js:** `v24.19.0`
- **Auto-Detected on Machine:** `opencode` (`v2.4.1`), `antigravity` (`agy 1.4.12`), `claude-code` (`2.1.110`), `gemini-cli` (`0.46.0`)
- **Live-Authenticated Providers Benchmarked:** `opencode` (`opencode-go/deepseek-v4.1-flash`) + `antigravity` (`agy`)

### 1. Parallel Fan-Out & Lead Blocking (Same-Provider & Cross-IDE)

| Benchmark Scenario | Direct CLI (Cold / Seq) | Direct CLI (Warm / Seq) | `cli-orchestrator-mcp` (Async Parallel) | Lead Blocking (Dispatch) | Measured Speedup |
| :--- | :---: | :---: | :---: | :---: | :--- |
| **OpenCode: 3-Task Fan-Out** | 12,063 ms | 5,762 ms | **2,013 ms** | **135 ms** | **5.99×** vs cold / **2.86×** vs warm seq |
| **Cross-IDE: 2× OpenCode + 1× Antigravity** | — | 27,975 ms | **9,558 ms** | **25 ms** | **2.93× faster** (**1,119×** less Lead blocking) |

```text
Cross-IDE (2x OpenCode + 1x Antigravity):
  Direct CLIs (sequential)       ████████████████████████████████████████  27,975 ms
  MCP Parallel (all 3 at once)   ██████████████                             9,558 ms  (2.93x faster)
  └─ OpenCode Worker #1          ██                                         1,175 ms
  └─ OpenCode Worker #2          ██                                         1,319 ms
  └─ Antigravity Worker #3       ██████████████                             9,532 ms
  Lead dispatch blocking time    ▏                                             25 ms  (non-blocking)
```

### 2. Single-Task & Multi-Turn Session Continuation

| Provider | Single Task (Direct CLI) | Single Task (MCP) | Session Turn 1 | Session Turn 2 (`session_id`) | Turn 2 Prompt Cache Hit |
| :--- | :---: | :---: | :---: | :---: | :--- |
| **OpenCode** (`deepseek-v4.1-flash`) | 3,547 ms (cold) / 1,409 ms (warm) | 2,291 ms | 1,772 ms | **1,208 ms** | **7,552 cached** vs 148 new (**98.1% hit**) |
| **Antigravity** (`agy` default model) | 33,145 ms | 13,073 ms | 9,120 ms | **6,745 ms** | **10,048 cached** tokens |

### Key Takeaways
1. **Cross-IDE parallelism hides slow workers:** In the `2× OpenCode + 1× Antigravity` test, both OpenCode workers completed in `~1.2s` *while* Antigravity was still reasoning (`9.5s`), reducing total wall-clock time from `27.98s` to `9.56s` (**2.93× faster**) while blocking the Lead for only **25 ms**.
2. **Same-provider scaling is nearly 6× faster than cold CLI:** `12,063 ms` (`--standalone` sequential) drops to `2,013 ms` via warm-service async MCP (**5.99×**).
3. **Stateful revisions stay fast across providers:** Both OpenCode (`--session`) and Antigravity (`--conversation`) preserved context accurately (`17 × 3 = 51`, `12 × 4 = 48`) with massive prompt-cache reuse (`98.1%` on OpenCode).

### Reproduce on Your Machine

```bash
npm run bench
# Or target a specific OpenCode model:
BENCH_MODEL=opencode/claude-fable-5-2 npm run bench
```

---

## MCP Tool Reference

| Tool | Description | Key Parameters |
| :--- | :--- | :--- |
| `worker_list_providers` | Auto-detects all 7 supported local AI CLIs (60s cached, `<1 ms`). | `refresh?` |
| `worker_service_status` | Checks/starts a provider's background daemon (if applicable). | `provider`, `ensure_running?` |
| `worker_list_models` | Lists available models for a provider (`opencode`, `antigravity`). | `provider`, `filter?`, `refresh?` |
| `worker_start_task` | Starts an async worker task with priority queuing, auto-retry, and worktree locking. | `provider`, `prompt`, `model?`, `cwd?`, `session_id?`, `worktree?`, `priority?`, `max_retries?`, `auto_approve?`, `timeout_seconds?`, `wait_seconds?` |
| `worker_run_workflow` | Executes a **DAG Dependency Graph** (`depends_on` + `{{nodeId.output}}` interpolation, cycle detection, failure skip cascade). | `name?`, `tasks[]`, `wait_seconds?` |
| `worker_get_workflow` | Gets live status and per-node outputs of a running or completed DAG workflow. | `workflow_id`, `wait_seconds?` |
| `worker_get_task` | Gets status, output, `session_id`, tokens, and tool events (falls back to disk after restarts). | `task_id`, `wait_seconds?` (0–60s), `max_output_chars?` |
| `worker_wait_tasks` | Waits for multiple parallel tasks in **one MCP call** (`mode: "all" \| "any"`). | `task_ids`, `mode?`, `wait_seconds?`, `max_output_chars?` |
| `worker_list_tasks` | Lists all worker tasks (`queued`, `running`, `completed`, `failed`, `timed_out`, `cancelled`). | `provider?`, `status?` |
| `worker_cancel_task` | Cleanly terminates a queued or running worker process tree. | `task_id` |
| `worker_cleanup_worktree` | Safely removes a temporary git worktree (blocked if an active task holds its lock). | `worktree`, `cwd?`, `delete_branch?` |
| `worker_stats` | Returns per-provider metrics: success rate, avg latency, retries, token usage, cost, and active queue state. | *(none)* |

### Example: Multi-Agent DAG Workflow (`worker_run_workflow`)

```json
{
  "name": "feature-pipeline",
  "wait_seconds": 30,
  "tasks": [
    { "id": "backend", "provider": "claude-code", "worktree": "feat-api", "prompt": "Build POST /api/settings" },
    { "id": "frontend", "provider": "opencode", "model": "opencode-go/deepseek-v4.1-flash", "worktree": "feat-ui", "prompt": "Build SettingsModal UI" },
    { "id": "integration", "provider": "codex", "depends_on": ["backend", "frontend"], "prompt": "Wire UI to API. Backend: {{backend.output}} Frontend: {{frontend.output}}" },
    { "id": "review", "provider": "gemini-cli", "depends_on": ["integration"], "prompt": "Review integration: {{integration.output}}" }
  ]
}
```

### Built-in Performance & Orchestration Highlights
- **DAG pipelines (`worker_run_workflow`):** Run parallel stages with `depends_on`, `{{nodeId.output}}` interpolation, cycle detection, and automatic downstream skip-on-failure.
- **Priority concurrency queue & auto-retry:** Cap concurrent workers via `CLI_ORCHESTRATOR_MAX_CONCURRENT`, prioritize urgent tasks with `priority`, and recover automatically with `max_retries`.
- **Batch collection (`worker_wait_tasks`):** Collect N parallel workers in 1 round-trip (`mode: "all"` or `"any"`) instead of polling each task individually.
- **Proactive daemon warm-up:** Automatically warms up installed background daemons on MCP `initialize` so the first task hits zero cold-start latency.
- **Zero-reinstall worktrees (`link_deps: true`):** Automatically creates OS-native junctions/symlinks for `node_modules` & `.venv` (while keeping `.env` files isolated unless `copy_env: true` is opted in).
- **Non-blocking I/O & caching:** Async `fs.promises` task snapshots + 60s provider/model discovery caches keep the JSON-RPC loop unblocked.
- **Lead context protection (`max_output_chars`):** Cap huge worker logs inline while returning `log_path` to inspect full output on demand.

### Example: Dispatching Two Different IDEs in Parallel

```json
// Call 1 — OpenCode worker on isolated worktree
{
  "tool": "worker_start_task",
  "arguments": {
    "provider": "opencode",
    "model": "opencode-go/deepseek-v4.1-flash",
    "prompt": "Implement the responsive settings modal in src/components/SettingsModal.tsx",
    "worktree": "feat-settings-ui",
    "auto_approve": true,
    "wait_seconds": 0
  }
}

// Call 2 — Claude Code or Antigravity worker on another worktree (same turn!)
{
  "tool": "worker_start_task",
  "arguments": {
    "provider": "claude-code",
    "model": "sonnet",
    "prompt": "Write integration tests for POST /api/settings in tests/settings.test.ts",
    "worktree": "feat-settings-tests",
    "auto_approve": true,
    "wait_seconds": 0
  }
}
```

---

## Quick Start (Zero-Clone via `npx`)

Check which local AI CLIs are installed and ready on your machine:

```bash
npx -y github:cancakmk/cli-orchestrator-mcp --doctor
```

### Antigravity / Cursor / Windsurf / Cline / Roo Code
Add to `mcp_config.json` (or `.cursor/mcp.json`):
```json
{
  "mcpServers": {
    "cli-orchestrator": {
      "command": "npx",
      "args": ["-y", "github:cancakmk/cli-orchestrator-mcp"]
    }
  }
}
```

### Claude Code
```bash
claude mcp add cli-orchestrator -- npx -y github:cancakmk/cli-orchestrator-mcp
```

### VS Code (GitHub Copilot MCP)
Add to `.vscode/mcp.json`:
```json
{
  "servers": {
    "cli-orchestrator": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "github:cancakmk/cli-orchestrator-mcp"]
    }
  }
}
```

### Local Clone (For Development / Offline Use)
```bash
git clone https://github.com/cancakmk/cli-orchestrator-mcp.git
cd cli-orchestrator-mcp
npm test
# Point your IDE MCP config to: node /absolute/path/to/cli-orchestrator-mcp/server/index.mjs
```

---

## Lead Orchestration Skill (Optional)

**No extra setup required:** `cli-orchestrator-mcp` automatically sends core Lead orchestration instructions via the standard MCP `initialize.instructions` field as soon as your IDE connects.

For deeper customization, you can also copy [`skills/cli-orchestrator-lead/SKILL.md`](skills/cli-orchestrator-lead/SKILL.md) into your IDE's skills folder.

## Configuration & Environment Variables

| Variable | Default | Description |
| :--- | :--- | :--- |
| `CLI_ORCHESTRATOR_TASKS_DIR` | `~/.cli-orchestrator-mcp/tasks` | Directory where task JSON snapshots are persisted (falls back to `os.tmpdir()`). |
| `CLI_ORCHESTRATOR_MAX_CONCURRENT` | `4` | Maximum number of workers running simultaneously (extra tasks enter `queued` priority order). |
| `CLI_ORCHESTRATOR_MAX_STDOUT_BYTES` | `4194304` (4 MB) | In-memory `stdout` cap per worker to prevent OOM (`memory_capped: true`). |
| `CLI_ORCHESTRATOR_MAX_STDERR_BYTES` | `524288` (512 KB) | In-memory `stderr` ring-buffer cap per worker. |
| `CLI_ORCHESTRATOR_EXCLUDE` | *(none)* | Comma-separated provider IDs to disable (e.g. `claude-code,aider`). |
| `CLI_ORCHESTRATOR_ALLOWED_ROOTS` | *(unrestricted)* | Workspace allowlist (`;` on Windows / `:` on Unix or comma-separated) restricting allowed `cwd` paths. |
| `CLI_ORCHESTRATOR_STRIP_ENV` | *(none)* | Comma-separated env variable names or `PREFIX_*` wildcards stripped before spawning workers (e.g. `AWS_*,DATABASE_URL`). |
| `CLI_ORCHESTRATOR_HOST` | Auto-detected | Optional explicit host client ID override for the self-invocation guard. |
| `CLI_ORCHESTRATOR_MAX_DEPTH` | `1` | Maximum nesting depth (`CLI_ORCHESTRATOR_DEPTH`) before recursion is blocked. |
| `OPENCODE_BIN`, `AGY_BIN`, `CLAUDE_BIN`, `GEMINI_BIN`, `CODEX_BIN`, `CURSOR_BIN`, `AIDER_BIN` | Auto-detected | Optional explicit binary path override per CLI provider. |
| `BENCH_MODEL` | `opencode-go/deepseek-v4.1-flash` | Model used by `npm run bench` for OpenCode runs. |

## Security, Reliability & Recursion Guard

- **Zero credentials stored & secret isolation:** Uses only your locally authenticated CLI sessions. New git worktrees link `node_modules`/`.venv` by default but **never copy `.env` files** unless `copy_env: true` is explicitly passed. Strip sensitive host variables from child processes via `CLI_ORCHESTRATOR_STRIP_ENV`.
- **Workspace allowlist (`CLI_ORCHESTRATOR_ALLOWED_ROOTS`):** Restricts all worker `cwd` and cleanup operations to approved root directories (with `realpath` traversal protection).
- **Safe worktree lifecycle & locking:** Prevents two active workers from mutating the same `worktree` simultaneously, blocks `worker_cleanup_worktree` while a task owns it, and refuses to delete worktrees with uncommitted changes unless `force: true` is passed.
- **Process-tree termination & hard timeouts:** Kills full process trees on both Windows (`taskkill /T /F`) and POSIX (`detached: true` + `process.kill(-pid)`), with configurable `timeout_seconds` (default `300s`, status `timed_out`) and graceful `SIGINT`/`SIGTERM` shutdown.
- **Bounded memory & restart recovery:** Caps in-memory `stdout` (`4 MB`) and `stderr` (`512 KB`) to prevent OOM from noisy workers, while persisting task snapshots to disk for cross-restart `worker_get_task` lookup.
- **Automatic Self-Invocation & Recursion Guards:** Detects the host MCP client (`clientInfo.name`), blocks self-invocation unless `allow_self: true`, supports `CLI_ORCHESTRATOR_EXCLUDE`, and enforces `CLI_ORCHESTRATOR_DEPTH` to make infinite loops impossible.

## License

[MIT](LICENSE)