claude-mcp-bridge
MCP server bridging Claude CLI to Gemini CLI, Codex, Cursor - queries, and search with hardened subprocess management
README
claude-mcp-bridge
MCP server that wraps Claude Code CLI as a subprocess, exposing its capabilities as Model Context Protocol tools.
Works with any MCP client: Codex CLI, Gemini CLI, Cursor, Windsurf, VS Code, or any tool that speaks MCP.
Do you need this?
If you're in a terminal agent (Codex CLI, Gemini CLI) with shell access, call Claude Code CLI directly:
# Analyze specific files
claude -p --bare --allowed-tools "Read" "Analyze src/utils/parse.ts for edge cases"
# With budget cap
claude -p --bare --max-budget-usd 0.50 "Is this retry logic sound?"
--bare skips hooks, memory, and plugins for clean subprocess use. --allowed-tools controls exactly what Claude can access. --max-budget-usd prevents runaway costs.
For code review, see Code review (without this bridge).
Use this MCP bridge instead when:
- Your client has no shell access (Cursor, Windsurf, Claude Desktop, VS Code)
- You need structured output with native
--json-schemavalidation - You need session resume across calls (
--resume SESSION_ID) - You need concurrency management and security hardening
- You want cost metadata surfaced in MCP responses
Quick Start
npx claude-mcp-bridge
Prerequisites
- Claude Code CLI installed and on PATH
- Authentication (one of):
- Subscription (default):
claude login(uses your Pro/Max plan, no API credits needed) - API key: set
ANTHROPIC_API_KEY+CLAUDE_BRIDGE_USE_API_KEY=1(billed per use via console.anthropic.com)
- Subscription (default):
Codex CLI
Add to ~/.codex/config.json:
{
"mcpServers": {
"claude-bridge": {
"command": "npx",
"args": ["-y", "claude-mcp-bridge"]
}
}
}
Gemini CLI
Add to ~/.gemini/settings.json:
{
"mcpServers": {
"claude-bridge": {
"command": "npx",
"args": ["-y", "claude-mcp-bridge"]
}
}
}
Cursor / Windsurf / VS Code
Add to your MCP settings:
{
"claude-bridge": {
"command": "npx",
"args": ["-y", "claude-mcp-bridge"],
"env": {
"ANTHROPIC_API_KEY": "sk-ant-...",
"CLAUDE_BRIDGE_USE_API_KEY": "1"
}
}
}
Tools
| Tool | Description |
|---|---|
| query | Execute prompts with file context, session resume, effort control, and budget caps. Supports text and images. For code review, see Code review (without this bridge). |
| search | Web search via Claude CLI's WebSearch and WebFetch tools. Returns synthesized answers with sources. |
| structured | JSON Schema validated output via Claude CLI's native --json-schema. |
| ping | Health check with CLI version, auth method, capabilities, and model config. |
| listSessions | List active sessions with cumulative cost, turn count, and timestamps. |
query
Execute a prompt with optional file context. Supports session resume via sessionId, effort control (low/medium/high/max), and budget caps (maxBudgetUsd). Images (.png, .jpg, .gif, .webp, .bmp) up to 5MB each are passed to Claude's Read tool.
Key parameters: prompt (required), files, model (default sonnet), sessionId, effort, maxBudgetUsd, workingDirectory, timeout (default 60s).
search
Web search powered by Anthropic's WebSearch tool via Claude CLI. Returns synthesized answers with source URLs.
Key parameters: query (required), model (default sonnet), maxResponseLength, maxBudgetUsd, timeout (default 120s).
structured
Generate JSON conforming to a provided schema using Claude CLI's native --json-schema flag. Returns clean JSON in the first content block, metadata in a separate block so JSON parsing isn't broken.
Key parameters: prompt (required), schema (required, JSON string, max 20KB), files, model (default sonnet), sessionId, maxBudgetUsd, timeout (default 60s).
ping
No parameters. Returns CLI version, auth method (subscription/api-key/none), configured models, capabilities, and server version.
listSessions
No parameters. Returns active sessions with metadata: sessionId, model, createdAt, lastUsedAt, turnCount, totalCostUsd.
All tools attach execution metadata (_meta) with durationMs, model, sessionId, totalCostUsd, and token breakdowns. See DESIGN.md for details.
Configuration
Models
| Variable | Default | Description |
|---|---|---|
CLAUDE_DEFAULT_MODEL |
Shared default for all tools | |
CLAUDE_QUERY_MODEL |
sonnet |
Default for query |
CLAUDE_STRUCTURED_MODEL |
sonnet |
Default for structured |
CLAUDE_SEARCH_MODEL |
sonnet |
Default for search |
CLAUDE_FALLBACK_MODEL |
haiku |
Fallback on quota exhaustion (none to disable) |
Model resolution: explicit parameter > tool-specific env var > CLAUDE_DEFAULT_MODEL > built-in default.
Runtime
| Variable | Default | Description |
|---|---|---|
CLAUDE_MAX_CONCURRENT |
3 |
Max concurrent subprocess spawns |
CLAUDE_CLI_PATH |
claude |
Path to CLI binary |
CLAUDE_MAX_BUDGET_USD |
Global cost cap in USD (per call) | |
ANTHROPIC_API_KEY |
API key (only forwarded when CLAUDE_BRIDGE_USE_API_KEY=1) |
|
CLAUDE_BRIDGE_USE_API_KEY |
Set to 1 to forward ANTHROPIC_API_KEY to the subprocess (default: subscription auth) |
Effort
| Variable | Default | Description |
|---|---|---|
CLAUDE_SEARCH_EFFORT |
medium |
Default effort for search |
CLAUDE_QUERY_EFFORT |
Default effort for query |
Choosing a Claude Code MCP server
| You need... | Consider |
|---|---|
| Structured output, effort/budget control, session resume, cost metadata | This bridge |
| Multi-tool orchestration (read, grep, edit, bash as separate MCP tools) | mcp-claude-code |
| Session continuity with async execution | claude-mcp |
| Maintained lightweight wrapper | @kunihiros/claude-code-mcp |
| Native Claude Code MCP (built-in, no wrapper) | claude mcp serve (docs) |
Performance
Claude Code CLI has minimal startup overhead. Wall time is dominated by model inference and any agentic exploration.
| Scenario | Typical time |
|---|---|
| Trivial prompt (sonnet) | 5-10s |
| Web search + synthesis | 15-30s |
Cost metadata (totalCostUsd, token breakdowns) is returned in _meta on every response.
Bridge family
Three MCP servers, same architecture, different underlying CLIs. Each wraps a terminal agent as a subprocess and exposes it as MCP tools. Pick the one that matches your model provider, or run multiple for cross-model workflows.
| claude-mcp-bridge | gemini-mcp-bridge | codex-mcp-bridge | |
|---|---|---|---|
| CLI | Claude Code | Gemini CLI | Codex CLI |
| Provider | Anthropic | OpenAI | |
| Tools | query, search, structured, ping, listSessions | query, structured, search, fetch-chunk, ping | codex, search, query, structured, ping, listSessions |
| Code review | Use Claude Code built-ins directly (not via this bridge), or claude -p for non-Claude-Code hosts |
Use the gemini ecosystem (extension, skills, subagents, Code Assist) or gemini -p directly |
codex review --base <ref> (native) or codex tool with caller-supplied prompt |
| Structured output | Native --json-schema (no Ajv) |
Ajv validation | Ajv validation |
| Session resume | Native --resume |
Not supported | Session IDs with multi-turn |
| Budget caps | Native --max-budget-usd |
Not supported | Not supported |
| Effort control | --effort low/medium/high/max |
Not supported | Not supported |
| Cold start | ~1-2s | ~16s | <100ms (inference dominates) |
| Auth | claude login (default) or ANTHROPIC_API_KEY + opt-in |
gemini auth login |
OPENAI_API_KEY |
| Cost | Subscription (default) or API credits (opt-in) | Free tier available | Pay-per-token |
| Concurrency | 3 (configurable) | 3 (configurable) | 3 (configurable) |
| Model fallback | Auto-retry with fallback model | Not supported | Auto-retry with fallback model |
All three share: subprocess env isolation, path sandboxing, output redaction, FIFO concurrency queue, MCP tool annotations, _meta response metadata, progress heartbeats.
Code review (without this bridge)
This section explains how to do code review with the Claude Code CLI. The bridge isn't part of either path. Built-in slash commands run inside Claude Code's interactive REPL and aren't exposed via claude -p or MCP; direct claude -p invocation skips the bridge by definition. If you reached this page hoping the bridge has a review tool, see ADR-001 for why it was removed.
Route based on where you are:
- Already in Claude Code? Type
/review,/security-review, or/ultrareviewat the prompt. Skip the rest of this section. - Calling from another MCP host (Cursor, Codex CLI, Gemini CLI, Claude Desktop)? You can't reach review through this bridge. Use
claude -pdirectly per below, or use the host's own review surface if it has one.
Direct claude -p invocation (subprocess-isolated)
For shell-equipped consumers (terminal agents, CI, BYOS skills), invoke the CLI directly with hardened isolation flags:
claude -p \
--permission-mode plan \
--bare \
--add-dir <repo-root> \
--strict-mcp-config \
--mcp-config '{"mcpServers":{}}' \
--no-session-persistence \
--max-budget-usd 0.50 \
"<your review prompt + diff or file references>"
--permission-mode plan: read-only.--bare: strips parent's hooks, plugins, auto-memory, andCLAUDE.mdautoload.--add-dir <repo-root>: makes the repo'sCLAUDE.md/AGENTS.mdavailable where the diff warrants it.--strict-mcp-config --mcp-config '{"mcpServers":{}}': blocks parent's MCP servers from leaking in. The innermcpServerskey is required; the schema rejects bare'{}'.--no-session-persistence: no session files for one-off reviews.--max-budget-usd: per-call cost cap.
Claude Code skill template
For Claude Code users who want a reusable command, drop this into ~/.claude/commands/review-claude.md:
---
description: Code review via subprocess-isolated claude -p
---
Run code review on the diff between origin/main and HEAD.
```bash
claude -p \
--permission-mode plan \
--bare \
--add-dir "$(git rev-parse --show-toplevel)" \
--strict-mcp-config \
--mcp-config '{"mcpServers":{}}' \
--no-session-persistence \
--max-budget-usd 0.50 \
"Review the diff below for bugs, missing error handling on user input, tests modified to silence failures, and security issues (injection, missing auth checks, secret leaks). For each finding cite file:line, severity, and a suggested fix. Skip style/formatting.
$(git diff origin/main...HEAD)"
```
Representative review prompt
A starting point; adapt freely:
Review the following diff:
<diff content>
Look for:
- Bugs that would surface in production
- Missing error handling on user-supplied input
- Tests modified to silence failures rather than verify behaviour
- Security issues (injection, missing auth checks, secret leaks)
For each finding cite file:line, severity (high/medium/low), and a suggested fix.
Skip style/formatting; assume an autoformatter handles those.
Development
npm install
npm run build # Compile TypeScript
npm run dev # Watch mode
npm test # Run tests (vitest)
npm run lint # ESLint
npm run typecheck # tsc --noEmit
npm run smoke # Smoke test against live CLI
Further reading
- DESIGN.md - Architecture, sessions, cost tracking, response metadata, progress notifications
- SECURITY.md - Environment isolation, path sandboxing, output redaction, tool sandboxing
- CHANGELOG.md - Release history
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。