使用说明
克劳德代码MCP服务器
一种模型上下文协议(MCP)服务器,封装了Claude Code CLI,允许Claude实例通过自动子代理选择和规划将任务委托给其他Claude实例。
概述
此MCP服务器提供 claude_code 该工具:
- 使用智能子代理选择执行Claude Code CLI
- 执行前自动创建详细计划
- 支持工作区目录规范
- 提供所有活动的全面日志记录
特性
- 自动选择子代理:Claude根据任务性质智能地选择适当的子代理(代码审阅者、调试器、数据科学家、测试编写者、文档管理员或通用代理)
- 计划首次执行:在执行任务之前,始终制定详细的计划
- 递归问题分解:自动将复杂问题分解为更小的子任务,并将其委托给单独的Claude实例进行并行处理
- 工作区支持:文件操作的可选工作区目录规范
- 综合录井:记录的所有活动
[MCP]和[CLAUDE]前缀 - 保持活力设计:服务器持续运行,不会超时
安装
# Install dependencies
npm install
# Build the TypeScript code
npm run build
用法
运行服务器
启动MCP服务器:
npm run start > mcp-server.log 2>&1 &
检查服务器状态:
ps aux | grep "tsx src/index.ts" | grep -v grep
使用Claude代码
方法1:添加到克劳德代码(推荐)
使用 claude mcp add 添加MCP服务器的命令:
claude mcp add claude-code-mcp node /absolute/path/to/cc-mcp/dist/index.js
例如:
claude mcp add claude-code-mcp node /Users/sora/Documents/GitHub/cc-mcp/dist/index.js
然后,MCP服务器将在所有Claude Code会话中自动可用。
方法2:使用配置文件
添加到您的Claude Code MCP配置文件中:
{
"mcpServers": {
"claude-code-mcp": {
"command": "node",
"args": ["/absolute/path/to/cc-mcp/dist/index.js"]
}
}
}
然后在Claude Code中使用:
claude --mcp-config ./claude_mcp_config.json
MCP工具规格
工具: mcp__claude-code-mcp__claude_code
描述:执行Claude Code CLI,自动选择和规划子代理。
参数:
prompt(string,必填):要委派的任务或请求
它是如何工作的: 每个请求都会自动添加前缀:
Use the Task tool to handle this request. Choose the most appropriate subagent_type
based on the nature of the task (e.g., code-reviewer, debugger, data-scientist,
test-writer, documenter, or general-purpose).
Create a detailed plan first, then execute it step by step.
User request: {your_prompt}
示例:
- 简单任务:
Use mcp__claude-code-mcp__claude_code with prompt "Create a Python function to reverse a string"
建筑
Primary Claude Code Instance
↓
MCP Protocol (stdio)
↓
cc-mcp Server
├─ Automatic prefix injection
├─ Sub-agent selection instruction
└─ Planning requirement
↓
Claude Code CLI (--dangerously-skip-permissions --add-dir)
↓
Secondary Claude Instance
├─ Chooses appropriate sub-agent
├─ Creates detailed plan
└─ Executes step by step
↓
Response back through MCP
配置
服务器默认值
- 超时:60万毫秒(10分钟)
- 权限:始终跳过(
--dangerously-skip-permissions) - 环境:
NO_COLOR=1
文件结构
cc-mcp/
├── src/
│ └── index.ts # Main MCP server
├── dist/ # Built files
├── docs/
│ └── 요구사항명세서.md # Requirements (Korean)
├── claude_mcp_config.json # MCP configuration
├── package.json
└── README.md
发展
# Install dependencies
npm install
# Build
npm run build
# Run in development mode (auto-reload)
npm run dev
服务器管理
开始:
npm run start > mcp-server.log 2>&1 &
停止:
pkill -f "tsx src/index.ts"
重新启动:
pkill -f "tsx src/index.ts" && sleep 1 && npm run start > mcp-server.log 2>&1 &
检查是否正在运行:
ps aux | grep "tsx src/index.ts" | grep -v grep
需求
- Node.js 18+
- Claude Code CLI已安装并在PATH中可用
- TypeScript 5.0+
- 有效的Claude API密钥(用于Claude Code CLI)
许可证
国际协调委员会