cli-orchestrator-mcp

cli-orchestrator-mcp

Resilient multi-CLI orchestration server for AI agents that routes tasks to Claude, Gemini, or Codex with automatic retry, circuit breaker, and fallback.

Category
访问服务器

README

<p align="center"> <img src="assets/logo.svg" alt="cli-orchestrator-mcp" width="600" /> </p>

<p align="center"> <strong>Resilient multi-CLI orchestration server for AI agents</strong> </p>

<p align="center"> <a href="https://www.npmjs.com/package/cli-orchestrator-mcp"><img src="https://img.shields.io/npm/v/cli-orchestrator-mcp?color=6366f1&label=npm&style=flat-square" alt="npm version" /></a> <a href="https://github.com/lleontor705/cli-orchestrator-mcp/actions"><img src="https://img.shields.io/github/actions/workflow/status/lleontor705/cli-orchestrator-mcp/ci.yml?style=flat-square&label=CI" alt="CI" /></a> <img src="https://img.shields.io/node/v/cli-orchestrator-mcp?style=flat-square&color=10b981" alt="node" /> <a href="LICENSE"><img src="https://img.shields.io/npm/l/cli-orchestrator-mcp?style=flat-square&color=f59e0b" alt="license" /></a> </p>


Why cli-orchestrator-mcp?

Modern AI workflows often need more than one LLM CLI. Claude excels at reasoning, Gemini at research, Codex at code generation. But managing multiple CLIs — handling failures, retries, fallbacks, and routing — is complex and error-prone.

cli-orchestrator-mcp solves this by providing a single Model Context Protocol (MCP) server that:

  • Orchestrates Claude CLI, Gemini CLI, and Codex CLI through a unified interface
  • Routes intelligently — picks the best CLI based on the agent's role
  • Recovers automatically — retry with backoff, circuit breaker isolation, and provider fallback
  • Runs inline — executes CLIs as local subprocesses, no API keys or cloud calls needed

Any MCP-compatible client (Claude Code, Codex CLI, Gemini CLI, OpenCode, or custom agents) can use it out of the box.


Architecture

<p align="center"> <img src="assets/architecture.svg" alt="Architecture Overview" width="850" /> </p>

The server sits between your MCP client and the installed CLI tools. When a task arrives via cli_execute, it flows through the resilience pipeline — global time budget, circuit breaker check, process execution, retry logic, and fallback — before returning a redacted, safe response.


Quick Start

npx -y cli-orchestrator-mcp

Prerequisites: Node.js >= 18 and at least one CLI installed and authenticated:

CLI Install Auth
Claude npm i -g @anthropic-ai/claude-code claude (interactive login)
Gemini npm i -g @google/gemini-cli gemini (Google auth)
Codex npm i -g @openai/codex codex (OpenAI auth)

CLIs handle their own authentication inline — no API keys or environment variables required.


Configuration

Claude Code

claude mcp add cli-orchestrator --transport stdio -- npx -y cli-orchestrator-mcp

Codex CLI (~/.codex/config.toml)

[mcp_servers.cli-orchestrator]
command = "npx"
args = ["-y", "cli-orchestrator-mcp"]

Gemini CLI (settings.json)

{
  "mcpServers": {
    "cli-orchestrator": {
      "command": "npx",
      "args": ["-y", "cli-orchestrator-mcp"]
    }
  }
}

OpenCode (opencode.json)

mcp: {
  servers: {
    "cli-orchestrator": { command: "npx", args: ["-y", "cli-orchestrator-mcp"] }
  }
}

What is MCP and Why Use It?

Model Context Protocol (MCP) is an open standard that lets AI agents discover and use tools through a unified interface. Instead of hardcoding integrations, agents connect to MCP servers that expose capabilities as tools, resources, and prompts.

Why MCP for CLI orchestration?

Without MCP With cli-orchestrator-mcp
Each agent hardcodes CLI calls Agents call cli_execute — one interface for all CLIs
No retry, no fallback, no circuit breaker Full resilience pipeline built-in
Agent must know which CLI is installed Auto-detection — server discovers available CLIs
Agent handles errors and timeouts Server handles errors, redacts secrets, returns clean output
Switching CLI requires code changes Change the cli parameter — or let cli_route pick automatically

The goal: Let AI agents focus on what to do, not how to execute it reliably across multiple CLI tools.


MCP Tools

Tool Description
cli_execute Execute a task with full resilience (retry + circuit breaker + fallback)
cli_route Recommend the best CLI based on agent role
cli_stats Health dashboard — installation, circuit breaker, execution stats
cli_list List installed CLI providers with paths and strengths

cli_execute

The primary tool. Sends a prompt to a CLI provider with the full resilience pipeline.

Parameter Type Default Description
cli "claude" | "gemini" | "codex" required Target CLI provider
prompt string (max 100KB) required Prompt to send
mode "generate" | "analyze" "generate" Execution mode
timeout_seconds number (10–1800) 300 Global timeout budget (covers all retries and fallbacks)
allow_fallback boolean true Allow fallback to other CLIs on failure
cwd string Working directory for CLI execution

Returns: { success, provider, output, duration_ms, fallback_used, attempts, error? }

CLI arguments by provider:

Provider Generate mode Analyze mode
Claude -p <prompt> --allowedTools "" --max-turns N -p <prompt> --max-turns N
Gemini -e none -p <prompt> -e none -p <prompt>
Codex exec <prompt> --full-auto exec <prompt> --full-auto

--max-turns for Claude is calculated dynamically based on remaining timeout budget (~1 turn per 30s, min 2, max 25).

cli_route

Recommends the best available CLI for a given agent role.

Parameter Type Description
role "manager" | "coordinator" | "developer" | "researcher" | "reviewer" | "architect" Agent role
task_description string (optional) Task context for better routing

cli_stats

Returns per-provider health: installed status, path, circuit breaker state, execution/failure/timeout counts, and strengths.

cli_list

Returns all installed CLI providers with their binary paths and declared strengths.

MCP Resources

URI Description
mcp://cli-stats Real-time health dashboard (JSON)

MCP Prompts

Prompt Inputs Description
code_review code (required), language (optional) Code review for bugs, performance, best practices
architecture_design requirements (required) System architecture from requirements

Role-based Routing

<p align="center"> <img src="assets/role-routing.svg" alt="Role-based CLI Routing" width="750" /> </p>

Each agent role maps to a primary CLI based on its strengths, with automatic fallback to alternatives:

Role Primary Why Fallback Chain
Manager Gemini Research, trends, large-context analysis Claude → Codex
Coordinator Claude Reasoning, planning, architecture decisions Gemini → Codex
Developer Codex Code generation, refactoring, full-auto edits Claude → Gemini
Researcher Gemini Knowledge synthesis, web search Claude → Codex
Reviewer Claude Code analysis, debugging, quality review Gemini → Codex
Architect Claude System design, architecture patterns Gemini → Codex

Resilience Pipeline

<p align="center"> <img src="assets/resilience-pipeline.svg" alt="Resilience Pipeline" width="850" /> </p>

Global Time Budget

The entire chain — retries and fallbacks — shares a single time budget (default: 300s). Each attempt receives remainingSeconds, not the full timeout. This prevents the classic problem where 3 providers × 3 attempts × timeout = 9× the expected wait.

Circuit Breaker

Per-provider state machine with separate thresholds for hard failures and timeouts:

State Behavior
Closed Normal — track failures (threshold: 3) and timeouts (threshold: 5)
Open Reject all calls for 60s cooldown
Half-open Allow 1 test request — success closes, failure reopens

Timeouts use a higher threshold (5 vs 3) because a slow provider isn't necessarily broken.

Retry Policy

  • Max retries: 2 (3 total attempts per provider)
  • Backoff: Exponential (base 1s, max 10s) with ±30% jitter
  • Retryable: Rate limits (429), server errors (503), ECONNRESET, ETIMEDOUT
  • Non-retryable: Process timeouts (skip directly to fallback), auth errors, permanent failures

Abort Handling

AbortSignal propagates from MCP client through the entire pipeline:

  • Cancels running CLI process immediately via execa
  • Interrupts retry backoff sleep — no wasted wait time
  • Checked between every attempt and every provider

Progress Notifications

During execution, the server sends MCP progress notifications every 5 seconds with enriched context:

[claude] primary, attempt 1, 15s elapsed, 285s remaining
[gemini] fallback #1, attempt 1, 45s elapsed, 255s remaining

Security

Layer Protection
Environment Only essential system vars forwarded (PATH, HOME, TERM, proxy). CLIs authenticate inline.
Secrets API key patterns (sk-, key-, AIza) automatically redacted from all output and errors
Execution No shell — commands built as arrays, never string concatenation. No shell: true.
Prompts Large prompts (>30KB) sent via stdin to avoid OS arg-length limits
Process Each CLI runs in isolated subprocess with configurable timeout and buffer limits (10MB)

Development

git clone https://github.com/lleontor705/cli-orchestrator-mcp.git
cd cli-orchestrator-mcp
npm install
npm run build          # Compile TypeScript
npm run dev            # Run with tsx (no build)
npm test               # Unit tests (CI-safe, no CLIs needed)
npm run test:all       # All tests including stress & integration
npm run lint           # Type-check (tsc --noEmit)
npm run inspect        # Debug with MCP Inspector

Test Suites

Command Scope Environment
npm test Unit tests — definitions, detection, circuit breaker, resilience CI — fast, mocked
npm run test:local Integration + stress tests Local — requires real CLIs
npm run test:all All of the above Local

Stress tests cover: timeout enforcement, abort/cancellation, concurrent execution (10+), fallback chain timing, large output (5MB+), circuit breaker rapid-fire, large prompt stdin.

Project Structure

src/
  index.ts                  Entry point (stdio transport)
  server.ts                 MCP server factory
  cli/
    definitions.ts          CLI provider configs & arg builders
    detection.ts            Auto-detection with 5-min cache
    executor.ts             Process execution via execa
    circuit-breaker.ts      Per-provider state machine
    resilience.ts           Retry + fallback orchestration
  tools/
    orchestrator.ts         MCP tools, resources, prompts
  types/
    index.ts                TypeScript types & routing table
  utils/
    env-allowlist.ts        Safe environment filtering
    redact.ts               Secret redaction

Tech Stack

Component Technology
Runtime Node.js >= 18 (cross-platform)
Language TypeScript 5.7 (strict mode)
MCP SDK @modelcontextprotocol/sdk
Process exec execa
Circuit breaker Custom (lightweight, per-provider)
Validation Zod
Testing Vitest

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选