Claude Code MCP Bridge

Claude Code MCP Bridge

Exposes Claude Code's file editing, command execution, and test running capabilities as composable MCP tools for any MCP-compatible host, enabling code operations via a stateless bridge.

Category
访问服务器

README

Claude Code MCP Bridge

A stateless MCP (Model Context Protocol) server that exposes Claude Code's capabilities as individual tools for any MCP-compatible host to consume.

License: MIT Python 3.11+ MCP Built with FastMCP


Why This Exists

Claude Code is a powerful coding agent, but its primary interface is an interactive terminal. Hosting it as an MCP server lets any MCP-compatible agent or application invoke Claude Code's file editing, command execution, and test-running capabilities as discrete, composable tools — without pty management, terminal UI, or session lifecycle.

The stateless architecture was a deliberate tradeoff: each tool call spawns a fresh claude -p (print-mode) subprocess instead of maintaining a persistent session. This avoids the fragile prompt-pattern matching, first-run wizards, theme selectors, and pty state management that a persistent session requires. The cost is a ~5s cold-start latency per call; the benefit is zero session-related failures.

Tools

cc_execute_command

Run arbitrary commands through Claude Code. It handles shell execution, file system operations, package management, and any terminal-compatible task.

Parameter Type Description
command string (required) The command to execute
workdir string (optional) Working directory (defaults to current)
timeout integer (optional) Max seconds to wait (default 120)

Returns exit_code, stdout, stderr, and a truncated flag if output exceeded limits.

cc_edit_file

Make targeted edits to files using Claude Code's semantic understanding. Unlike raw sed or regex, this tool identifies the correct location even when indentation or minor formatting varies.

Parameter Type Description
path string (required) File to edit
old_string string (required) Existing text to replace
new_string string (required) Replacement text
language string (optional) Language hint for syntax-aware editing

Returns success, diff (unified format), syntax_ok, and warnings.

cc_run_tests

Run test commands through Claude Code and receive structured results. Parses test output into summary, failure details, and timing.

Parameter Type Description
command string (required) Test command to run
watch boolean (optional) Watch mode (default false)

Returns summary (total/passed/failed/skipped), failures array, and duration_seconds.

Quick Start

# Prerequisites
# - Python 3.11+
# - Claude Code installed and authenticated (claude command in PATH)
# - OPENAI_API_KEY or ANTHROPIC_API_KEY for Claude Code

git clone https://github.com/alexscarano/claude-code-mcp.git
cd claude-code-mcp

# Option A: uv (recommended)
uv sync
uv run python server.py

# Option B: pip
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python server.py

# Option C: run.sh (auto-detects uv or pip)
./run.sh

The server starts in stdio mode, which is the standard transport for MCP. Configure your MCP host to spawn the server as a subprocess.

Configuration

Variable Default Notes
CLAUDE_BIN claude Path to the Claude Code binary

Set via environment variable:

export CLAUDE_BIN=/path/to/claude
./run.sh

Architecture

MCP Host (e.g. Hermes Agent)
  │  stdio transport
  ▼
server.py (FastMCP entry point)
  │
  ├── cc_edit_file      → session._run() → claude -p ...
  ├── cc_execute_command → session._run() → claude -p ...
  └── cc_run_tests      → session._run() → claude -p ...

Each tool call:

  1. Builds a prompt from a template (templates.py)
  2. Forwards it to claude -p --dangerously-skip-permissions
  3. Extracts the structured <mcp-result> response from stdout
  4. Returns a validated dictionary to the caller

Note: The <mcp-result> wrapping ensures the MCP host receives structured JSON rather than conversational text. Claude Code is instructed to emit only this tagged block, and extract_result parses it with a regex pattern.

Constraints

  • Cold start: Each call spawns a fresh subprocess (~5s overhead). Not suited for high-frequency invocation.
  • Permission model: Uses --dangerously-skip-permissions. The tool's host is responsible for access control — review what commands are sent to the server.
  • Timeout handling: The server imposes a configurable per-call timeout (default 120s). Long-running commands may need adjustment.
  • Prompt size: Very large prompts (100KB+) increase processing time. The prompt is passed as a CLI argument, constrained by ARG_MAX (typically 2MB on Linux).

When to Use This vs Direct Claude Code

Use this bridge when:

  • Your primary agent needs occasional code modifications or analysis
  • You want composable tool invocations (call edit, then test, then commit)
  • You run in an environment where maintaining a persistent pty is impractical
  • You need structured, machine-parseable responses

Use Claude Code directly when:

  • You need an interactive coding session with back-and-forth
  • Latency per operation must be under 1 second
  • You want the full Claude Code TUI experience

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选