Claude Desktop API Integration via MCP

Claude Desktop API Integration via MCP

site icon
2025.01.19 6
PythonAPI集成对话管理系统提示开发效率交流协作
该项目提供了一个MCP服务器实现,用于无缝集成Claude Desktop和Claude API。它允许用户绕过专业版计划限制,访问自定义系统提示和对话管理等高级功能。
View on GitHub

Overview

基本能力

产品定位

Claude Desktop API Integration via MCP 是一个中间件服务,旨在桥接Claude Desktop应用与Claude API,提供更灵活的功能使用方式。

核心功能

  • 通过MCP直接集成Claude API
  • 对话历史跟踪和管理
  • 支持系统提示
  • 无缝切换专业版计划和API使用
  • 与Claude Desktop轻松配置

适用场景

  • 专业版计划(默认):
  • Claude Desktop中的常规对话
  • 在计划限制内的基本使用
  • 无需特殊配置

  • API令牌(通过此MCP服务器):

  • 需要更长的上下文窗口时
  • 使用自定义系统提示时
  • 绕过速率限制时
  • 进行高级对话管理时

工具列表

  1. query_claude
  2. 直接向Claude发起API调用
  3. 支持系统提示
  4. 对话跟踪

  5. clear_conversation

  6. 重置对话历史
  7. 管理多个对话线程

  8. get_conversation_history

  9. 检索对话记录
  10. 调试对话流程

常见问题解答

  1. API密钥问题
  2. 验证.env中的API密钥
  3. 检查Claude Desktop配置路径
  4. 确保API密钥具有正确的权限

  5. 连接问题

  6. 检查MCP服务器是否正在运行
  7. 验证Python环境
  8. 检查Claude Desktop日志

  9. 使用问题

  10. 确保正确的@claude-api语法
  11. 检查对话ID
  12. 验证系统提示格式

使用教程

使用依赖

pip install -r requirements.txt

安装教程

  1. 克隆仓库
git clone https://github.com/mlobo2012/Claude_Desktop_API_USE_VIA_MCP.git
cd Claude_Desktop_API_USE_VIA_MCP
  1. 配置环境
cp .env.example .env
# 编辑.env并添加您的API密钥
ANTHROPIC_API_KEY=your_api_key_here
  1. 配置Claude Desktop
  2. macOS: 导航到~/Library/Application Support/Claude/
  3. Windows: 导航到%APPDATA%\Claude\
  4. 创建或编辑claude_desktop_config.json
  5. config/claude_desktop_config.json复制内容
  6. 更新路径和API密钥

调试方式

  1. 基本使用
@claude-api Please answer using the API: What is the capital of France?
  1. 高级功能
@claude-api {"system_prompt": "You are an expert fitness coach"} Create a workout plan
  1. 管理对话
# 开始新对话
@claude-api {"conversation_id": "project1"} Let's discuss Python

# 继续相同对话
@claude-api {"conversation_id": "project1"} Tell me more

# 查看对话历史
@claude-api get_conversation_history project1

# 清除对话
@claude-api clear_conversation project1

许可证

该项目遵循 MIT 开源许可条款。