Claude Code MCP Bridge

Claude Code MCP Bridge

A transparent message ferry between Claude Desktop and Claude Code CLI, enabling task delegation with any MCP configuration without the bridge needing to know about specific MCPs.

Category
访问服务器

README

Claude Code MCP Bridge

A pure message ferry between Claude Desktop and Claude Code CLI - MCP-agnostic and zero-overhead.

This MCP (Model Context Protocol) server creates a transparent bridge that allows Claude Desktop to delegate tasks to Claude Code CLI with any MCP configuration, without the bridge needing to know about specific MCPs.

Architecture: Pure Ferry Pattern

The bridge is a simple message conduit with zero knowledge of MCPs:

Claude Desktop/Code (Caller)
    ↓ Provides MCP config path
Bridge (Pure Ferry)
    ↓ Passes config transparently
Claude Code Subprocess
    ↓ Loads ANY MCP from config
Results flow back

Key Principle: The bridge never knows which MCPs exist. It simply:

  1. Accepts execution requests with optional MCP config paths
  2. Spawns Claude Code with that config
  3. Returns results
  4. Stays MCP-agnostic forever

Features

  • Zero MCP Knowledge: Bridge has no hardcoded MCP contexts
  • Unlimited Scalability: Works with any MCP - present or future
  • Minimal Token Overhead: Only 4 tools, regardless of MCP count
  • Simple Architecture: Pure message passing, no orchestration logic
  • Full Claude Code Access: All subagents, tools, and capabilities
  • Streaming Responses: Real-time progress updates
  • Session Management: Track and monitor active sessions
  • Session Persistence: OAuth sessions persist across Desktop restarts
  • Auto-Authentication: Seamless OAuth flow with browser auto-open
  • Rate Limit Protection: Intelligent authentication caching prevents rate limits

Quick Start

Prerequisites

  • Node.js 18+
  • Claude Code CLI installed and in PATH
  • Claude Desktop installed

Installation

# Clone and setup
git clone https://github.com/MagicTurtle-s/claude-code-mcp-bridge.git
cd claude-code-mcp-bridge
npm install
npm run build

Configure Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "claude-code-bridge": {
      "command": "node",
      "args": ["/path/to/claude-code-mcp-bridge/build/index.js"],
      "env": {
        "DEBUG": "false",
        "CLAUDE_CODE_PATH": "claude"
      }
    }
  }
}

Verify Setup

Restart Claude Desktop. The bridge should start automatically and expose 4 tools.

Available Tools

The bridge provides 4 generic, MCP-agnostic tools:

1. execute_task

Execute any task with Claude Code, optionally with MCP context.

Parameters:

  • prompt (required): The task to execute
  • mcpConfigPath (optional): Path to MCP configuration file (caller provides)
  • timeout (optional): Timeout in milliseconds (default: 120000)
  • permissionMode (optional): plan | acceptEdits | default | bypassPermissions
  • streamProgress (optional): Enable streaming updates (default: true)

Example:

execute_task({
  prompt: "Search codebase for authentication patterns",
  mcpConfigPath: "/tmp/my-mcp-config.json" // Optional
})

2. execute_with_tools

Execute with specific tool filtering.

Parameters:

  • prompt (required): The task to execute
  • allowedTools (optional): Array of allowed tool patterns
  • disallowedTools (optional): Array of disallowed tool patterns
  • mcpConfigPath (optional): Path to MCP config
  • timeout (optional): Timeout in milliseconds

Example:

execute_with_tools({
  prompt: "Analyze code structure",
  allowedTools: ["Read", "Grep", "Glob"],
  disallowedTools: ["Write", "Edit"]
})

3. execute_with_permission_mode

Execute with specific permission mode.

Parameters:

  • prompt (required): The task to execute
  • permissionMode (required): plan | acceptEdits | default | bypassPermissions
  • mcpConfigPath (optional): Path to MCP config
  • timeout (optional): Timeout in milliseconds

Example:

execute_with_permission_mode({
  prompt: "Analyze what changes are needed",
  permissionMode: "plan"
})

4. get_session_info

Get information about a Claude Code session.

Parameters:

  • sessionId (required): The session ID to query

Using with MCPs

The bridge doesn't know about MCPs - the caller manages MCP configurations.

Example: Using with Asana MCP

Step 1: Create MCP config file

// Caller creates this file
const fs = require('fs');
const configPath = '/tmp/my-asana-config.json';

fs.writeFileSync(configPath, JSON.stringify({
  mcpServers: {
    asana: {
      type: "sse",
      url: "https://asana-mcp-railway-production.up.railway.app"
    }
  }
}));

Step 2: Call bridge with config path

execute_task({
  prompt: "Search Asana for tasks assigned to Butch",
  mcpConfigPath: configPath
})

Step 3: Bridge spawns Code with that config

# Bridge runs this internally:
claude --mcp-config /tmp/my-asana-config.json --print "Search Asana for tasks..."

Result: Code loads Asana MCP and executes the task. Bridge never knew what "Asana" was.

Benefits of This Approach

Add new MCPs without code changes - Just create different config files ✅ Zero token overhead growth - Bridge always has 4 tools ✅ Full flexibility - Mix and match any MCPs in your configs ✅ True separation of concerns - Bridge ferries messages, caller manages MCPs

Migration from v1.x

v2.0.0 removed MCP-specific delegation tools to restore the pure ferry architecture.

What Changed

Removed:

  • delegate_hubspot_task
  • delegate_asana_task
  • delegate_sharepoint_task
  • delegate_batch_tasks

Reason: These tools created coupling between bridge and MCPs, defeating the token-saving purpose.

How to Migrate

Before (v1.x):

delegate_asana_task({
  prompt: "Search for tasks"
})

After (v2.0):

// You manage the MCP config
const configPath = "/tmp/asana-config.json";
fs.writeFileSync(configPath, JSON.stringify({
  mcpServers: { asana: { type: "sse", url: "..." } }
}));

// Use generic tool
execute_task({
  prompt: "Search for tasks",
  mcpConfigPath: configPath
})

Architecture Details

Why "Ferry" Instead of "Orchestrator"?

Ferry Pattern (v2.0):

  • Bridge has no MCP knowledge
  • Caller provides configs
  • Scales infinitely
  • Simple codebase

Orchestrator Pattern (v1.x - removed):

  • Bridge had hardcoded MCP contexts
  • Generated configs internally
  • Required code changes for new MCPs
  • Violated single responsibility

Data Flow

1. Caller creates MCP config file (if needed)
2. Caller calls execute_task with mcpConfigPath
3. Bridge receives request
4. Bridge spawns: claude --mcp-config <path> --print "<prompt>"
5. Code subprocess loads MCPs from config
6. Code executes task with MCP tools
7. Results stream back through bridge
8. Bridge returns results to caller
9. Bridge never inspected the config

Code Structure

Minimal, focused codebase:

src/
├── index.ts              # Entry point
├── server.ts             # MCP server (4 tools)
├── executor.ts           # Code subprocess spawner
├── session-manager.ts    # Session lifecycle
├── types.ts              # Type definitions
└── tools/
    └── index.ts          # 4 generic tools

No MCP-specific code anywhere!

Development

Build

npm run build

Development Mode

npm run dev  # Watch mode

Testing

# Test basic execution
node test-executor.js

# Test with MCP config
# (Create a test config first, then run)

Troubleshooting

Bridge Not Starting

  • Check Claude Desktop logs: %APPDATA%\Claude\logs\
  • Verify Node.js version: node --version (needs 18+)
  • Check Claude Code path: claude --version

No Output from Tasks

  • Ensure --verbose flag is used in executor (built-in since v1.0.1)
  • Check executor closes stdin (built-in since v1.0.1)
  • Enable debug mode: Set DEBUG: "true" in config

MCP Config Not Loading

  • Verify config file exists at the path you provided
  • Check JSON syntax in config file
  • Ensure MCP URLs are accessible
  • Remember: Bridge doesn't validate configs - Code does

Railway MCP Connection Issues

  • See comprehensive guide: docs/RAILWAY-SSE-DEBUGGING.md
  • Quick check: curl https://your-mcp.railway.app/health
  • Known Issue: Claude Code v2.0.45 has SSE transport bugs - use stdio for production

MCP Transport Compatibility

The bridge supports all MCP transport types, but Claude Code CLI has varying compatibility:

Transport Claude Code v2.0.45 Production Ready Recommended For
stdio ✅ Works perfectly ✅ Yes Client deployments
SSE ❌ Broken (3 bugs) ❌ No ⚠️ Wait for Claude Code fix
HTTP ❓ Untested ❓ Unknown ❓ TBD

Transport Recommendations

For Production Client Deployments:

{
  "mcpServers": {
    "hubspot": {
      "type": "stdio",
      "command": "node",
      "args": ["C:/path/to/hubspot-mcp/dist/index.js"],
      "env": {
        "HUBSPOT_ACCESS_TOKEN": "your-token"
      }
    }
  }
}

Avoid SSE Until Fixed (Claude Code v2.0.45 bugs):

  • Missing Accept: text/event-stream headers
  • GET vs POST confusion for handshakes
  • SSE stream parsing failures

See PRODUCTION-MIGRATION.md for detailed transport compatibility information.

Use Cases

1. Desktop Delegates to Code

Claude Desktop uses the bridge to leverage Code's powerful subagents.

2. Code Delegates to Code with MCPs

Global Code instance (with bridge) delegates to subprocess with specific MCP context.

3. Automated Workflows

Scripts call bridge tools programmatically with various MCP configs.

Technical Details

Session Management

  • Session Persistence: MCP OAuth sessions saved to %APPDATA%\Claude\.claude-mcp-sessions.json
  • Smart Validation: Saved sessions validated on startup, reused if still valid
  • Auto-Cleanup: Invalid sessions automatically purged
  • Rate Limit Protection: Local authentication caching prevents repeated OAuth prompts
  • Graceful Shutdown: Clean shutdown on SIGINT/SIGTERM
  • Event-Driven: Lifecycle hooks for monitoring
  • Security: Per-user file isolation with restrictive permissions

Streaming

  • Real-time progress updates via streaming JSON
  • Parses Claude Code's --output-format stream-json
  • Non-blocking, async I/O

Error Handling

  • Timeout protection (configurable)
  • Process cleanup on errors
  • Detailed error messages with context

Contributing

Contributions welcome! The architecture is intentionally simple:

Core Principle: The bridge must NEVER know about specific MCPs.

If a PR adds MCP-specific code, it will be rejected. The caller should manage MCP configurations.

License

MIT

Links

  • GitHub: https://github.com/MagicTurtle-s/claude-code-mcp-bridge
  • NPM: @magicturtle/claude-orchestrator (GitHub Packages)
  • Claude Code Docs: https://docs.claude.com/claude-code
  • MCP Specification: https://github.com/anthropics/mcp

Version

Current: 2.0.0 (Pure Ferry Architecture)

See CHANGELOG.md for version history.

推荐服务器

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

官方
精选