使用说明
Claude MCP服务器
MCP(模型上下文协议)服务器,用于将Claude CLI与Cursor和其他MCP兼容应用程序集成。允许通过方便的工具调用不同的Claude模型(Sonnet、Opus、Haiku)。
特性
- 🎯 多种型号:支持十四行诗、Opus和俳句
- 🔄 模型比较:同时从多个模型获取响应
- 📊 JSON响应:带有元数据的结构化响应
- 🎭 系统提示:使用自定义系统提示专门化模型行为
- 📦 批处理:按顺序处理多个提示
- 💬 对话连续性:根据上下文继续之前的对话
- 🛡️ 后备支援:自动回退到备份模型
- ⚡ 快速集成:在Cursor中简单设置
- 🔧 11强大的工具:适用于各种用例的全套工具
需求
- Node.js 18+
- 已安装Claude CLI(
claudePATH中的命令) - 游标或其他兼容MCP的应用程序
安装
- 克隆存储库或创建文件夹:
mkdir claude-mcp
cd claude-mcp
- 安装依赖项:
npm install
- 构建项目:
npm run build
该项目将在 dist/ 文件夹。
在游标中设置
macOS
-
打开MCP配置文件:
~/.cursor/mcp.json或者通过Finder:
Cmd+Shift+G→~/.cursor/mcp.json -
添加服务器配置:
{
"mcpServers": {
"claude": {
"command": "node",
"args": ["/Users/your_username/mcp/claude/dist/index.js"]
}
}
}
重要提示: 替换 /Users/your_username/mcp/claude 包含项目文件夹的完整路径。
视窗
-
打开配置文件:
%APPDATA%\Cursor\mcp.json -
添加配置:
{
"mcpServers": {
"claude": {
"command": "node",
"args": ["C:\\path\\to\\project\\claude-mcp\\dist\\index.js"]
}
}
}
Linux
-
打开文件:
~/.config/cursor/mcp.json -
添加配置:
{
"mcpServers": {
"claude": {
"command": "node",
"args": ["/home/your_username/mcp/claude/dist/index.js"]
}
}
}
替代选项(用于TypeScript开发)
如果你想在不构建的情况下使用源TypeScript:
{
"mcpServers": {
"claude": {
"command": "npx",
"args": ["tsx", "/full/path/to/claude/src/index.ts"]
}
}
}
安装后
- 完全重新启动游标 (关闭并重新打开)
- 工具将自动可用
可用工具
1. claude_call -环球克劳德电话
具有模型选择功能的基本工具。
参数:
prompt(字符串,必填)-提示发送model(字符串,可选)-型号:“十四行诗”、“小品”、“俳句”或完整型号名称
例子:
claude_call({
prompt: "Explain what TypeScript is",
model: "sonnet",
});
2. claude_sonnet -克劳德·索内特
快速访问Sonnet模型。
参数:
prompt(string)-提示
3. claude_opus -克劳德·奥普斯
快速访问Opus模型(功能最强大)。
参数:
prompt(string)-提示
4. claude_haiku -克劳德·海库
快速访问Haiku模型(最快)。
参数:
prompt(string)-提示
5. claude_json -JSON格式响应
返回带有元数据(执行时间、令牌、成本等)的结构化JSON。
参数:
prompt(string)-提示model(字符串,可选)-型号
示例响应:
{
"result": {
"type": "result",
"result": "Response text",
"duration_ms": 3509,
"usage": {
"input_tokens": 2,
"output_tokens": 57
},
"total_cost_usd": 0.07092975
},
"success": true
}
6. claude_with_system_prompt -带系统提示
允许设置系统提示以专门化模型行为。
参数:
prompt(string)-用户提示systemPrompt(string)-系统提示(模型角色)model(字符串,可选)-型号
例子:
claude_with_system_prompt({
prompt: "How can I improve this code?",
systemPrompt:
"You are a TypeScript and clean code expert. Answer briefly and to the point.",
model: "sonnet",
});
7. claude_compare_models -比较型号
同时从多个模型中获取响应以进行比较。
参数:
prompt(string)-提示models(array)-模型数组:[“十四行诗”、“小品”、“俳句”]
例子:
claude_compare_models({
prompt: "What is async/await?",
models: ["sonnet", "haiku"],
});
答复:
{
"results": {
"sonnet": {
"result": "Sonnet response...",
"success": true
},
"haiku": {
"result": "Haiku response...",
"success": true
}
},
"success": true
}
8. claude_batch -批量处理
按顺序处理多个提示并返回所有响应。
参数:
prompts(array)-要处理的提示数组model(字符串,可选)-用于所有提示的模型
例子:
claude_batch({
prompts: ["What is TypeScript?", "What is React?", "What is Node.js?"],
model: "sonnet",
});
答复:
{
"results": [
{
"prompt": "What is TypeScript?",
"result": "TypeScript is...",
"success": true
},
{
"prompt": "What is React?",
"result": "React is...",
"success": true
}
],
"success": true
}
9. claude_continue -继续对话
继续克劳德最近的对话,并带来新的信息。
参数:
prompt(string)-继续对话的新消息model(字符串,可选)-型号
例子:
claude_continue({
prompt: "Tell me more about that",
model: "sonnet",
});
注: 此工具使用 --continue 标记并维护之前对话的上下文。
10. claude_with_fallback -使用回退模型
使用回退模型调用Claude,该模型在主模型过载时激活。
参数:
prompt(string)-提示发送model(string)-主要型号fallbackModel(string)-如果主服务器过载,则使用回退模型
例子:
claude_with_fallback({
prompt: "Explain async/await",
model: "sonnet",
fallbackModel: "haiku",
});
11. claude_append_system_prompt -附加系统提示
调用Claude并将额外的上下文附加到默认系统提示中(不替换,而是添加)。
参数:
prompt(string)-用户提示appendSystemPrompt(string)-附加到系统提示的其他上下文model(字符串,可选)-型号
例子:
claude_append_system_prompt({
prompt: "Explain async/await",
appendSystemPrompt: "Answer in one sentence",
model: "haiku",
});
注: 不像 claude_with_system_prompt,这会附加到默认系统提示中,而不是替换它。
使用示例
比较不同的模型响应
使用 claude_compare_models 当你需要不同的视角时:
claude_compare_models({
prompt: "What are the advantages of TypeScript?",
models: ["sonnet", "opus", "haiku"]
})
专业响应
使用 claude_with_system_prompt 对于基于角色的场景:
claude_with_system_prompt({
prompt: "Review this code for errors",
systemPrompt: "You are an experienced code reviewer. Find bugs and provide constructive criticism.",
model: "sonnet"
})
结构化数据
使用 claude_json 要获取元数据,请执行以下操作:
claude_json({
prompt: "What is React?",
model: "sonnet"
})
适用于:
- 分析执行时间
- 跟踪请求成本
- 令牌使用统计
批处理
使用 claude_batch 一次处理多个提示:
claude_batch({
prompts: [
"What is TypeScript?",
"What are its advantages?",
"How to get started?"
],
model: "sonnet"
})
继续对话
使用 claude_continue 维护多条消息的上下文:
// First message
claude_call({
prompt: "My name is John",
model: "sonnet"
})
// Continue the conversation
claude_continue({
prompt: "What's my name?",
model: "sonnet"
})
可靠的请求
使用 claude_with_fallback 对于需要保证完成的关键请求:
claude_with_fallback({
prompt: "Important analysis task",
model: "sonnet",
fallbackModel: "haiku"
})
添加上下文
使用 claude_append_system_prompt 添加上下文而不替换默认值:
claude_append_system_prompt({
prompt: "Review this code",
appendSystemPrompt: "Focus on security issues",
model: "sonnet"
})
发展
以开发模式运行
npm run dev
建筑
npm run build
项目结构
claude-mcp/
├── src/
│ └── index.ts # Main server code
├── dist/ # Compiled code
├── package.json
├── tsconfig.json
└── README.md
故障排除
服务器未启动
- 检查以下路径
dist/index.js是正确的 - 确保你跑了
npm run build - 验证是否安装了Node.js:
node --version
工具未出现在光标中
- 完全重新启动Cursor (不仅仅是重新加载)
- 检查游标日志是否有错误
- 确保中的配置
mcp.json有效(检查JSON语法)
错误“找不到命令:claude”
确保Claude CLI已安装并在PATH中可用:
claude --version
如果找不到该命令,请根据官方文档安装Claude CLI。
TypeScript构建错误
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
npm run build
许可证
麻省理工学院
贡献
欢迎拉取请求!对于重大更改,请先打开一个问题来讨论您想要更改的内容。
作者
创建用于将Claude CLI与MCP生态系统集成。
