Claude Desktop API MCP

local-only server

The server can only run on the client’s local machine because it depends on local resources.

通过 MCP 集成 Claude 桌面 API

该项目提供了一个 MCP 服务器实现,可实现 Claude Desktop 与 Claude API 之间的无缝集成。它允许您绕过专业计划的限制,并使用自定义系统提示和对话管理等高级功能。

特征

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

何时使用

  • 专业计划(默认):
    • Claude Desktop 中的常规对话
    • 计划限制内的基本使用情况
    • 无需特殊配置
  • API 令牌(通过此 MCP 服务器):
    • 当您需要更长的上下文窗口时
    • 使用自定义系统提示
    • 绕过速率限制
    • 用于高级对话管理

设置说明

  1. 克隆存储库
    # Using VS Code: # 1. Press Cmd + Shift + P # 2. Type "Git: Clone" # 3. Paste: https://github.com/mlobo2012/Claude_Desktop_API_USE_VIA_MCP.git # Or using terminal: git clone https://github.com/mlobo2012/Claude_Desktop_API_USE_VIA_MCP.git cd Claude_Desktop_API_USE_VIA_MCP
  2. 安装依赖项
    pip install -r requirements.txt
  3. 配置环境
    # Copy environment template cp .env.example .env # Edit .env and add your API key ANTHROPIC_API_KEY=your_api_key_here
  4. 配置 Claude 桌面
    • macOS:导航至~/Library/Application Support/Claude/
      # Using Finder: # 1. Press Cmd + Shift + G # 2. Enter: ~/Library/Application Support/Claude/
    • Windows:导航至%APPDATA%\Claude\
    • 创建或编辑claude_desktop_config.json
    • config/claude_desktop_config.json复制内容
    • 更新路径和 API 密钥

使用指南

基本用法

  1. 常规 Claude 桌面使用情况
    • 和克劳德正常聊天就行
    • 使用您的专业计划
    • 无需特殊命令
  2. API 使用
    @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
  2. 管理对话
    # Start a new conversation @claude-api {"conversation_id": "project1"} Let's discuss Python # Continue same conversation @claude-api {"conversation_id": "project1"} Tell me more # View conversation history @claude-api get_conversation_history project1 # Clear conversation @claude-api clear_conversation project1

成本管理

  • API 调用使用您的 Anthropic API 积分,可能会产生费用
  • 使用专业计划进行常规查询
  • 仅在您特别需要时使用@claude-api:
    • 更长的上下文窗口
    • 自定义系统提示
    • 绕过速率限制

MCP 工具可用

  1. query_claude
    • 直接对 Claude 进行 API 调用
    • 支持系统提示
    • 对话追踪
  2. clear_conversation
    • 重置对话历史记录
    • 管理多个对话线程
  3. get_conversation_history
    • 检索对话记录
    • 调试对话流程

发展

主服务器实现位于src/claude_api_server.py中。要扩展功能,可以使用@mcp.tool()装饰器添加新工具。

添加新工具的示例:

@mcp.tool() async def custom_tool(param: str) -> str: """ Custom tool description Args: param: Parameter description """ try: # Tool implementation return result except Exception as e: return f"Error: {str(e)}"

故障排除

  1. API 密钥问题
    • 在 .env 中验证您的 API 密钥
    • 检查 Claude Desktop 配置路径
    • 确保 API 密钥具有正确的权限
  2. 连接问题
    • 检查 MCP 服务器是否正在运行
    • 验证 Python 环境
    • 检查 Claude Desktop 日志
  3. 使用问题
    • 确保@claude-api语法正确
    • 检查对话 ID
    • 验证系统提示格式

贡献

  1. 分叉存储库
  2. 创建功能分支
  3. 进行更改
  4. 提交拉取请求

执照

麻省理工学院

支持

对于问题和疑问:

  1. 在存储库中打开一个问题
  2. 检查现有讨论
  3. 查看故障排除指南

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

该服务器使 Claude Desktop 用户能够直接访问 Claude API,从而允许他们绕过专业计划限制并使用自定义系统提示和对话管理等高级功能。

  1. Features
    1. When to Use
      1. Setup Instructions
        1. Usage Guide
          1. Basic Usage
          2. Advanced Features
          3. Cost Management
        2. MCP Tools Available
          1. Development
            1. Troubleshooting
              1. Contributing
                1. License
                  1. Support
                    ID: riytk7nmma