ChatGPT API服务器

一个允许从Claude Desktop直接访问OpenAI ChatGPT API的MCP服务器,支持自定义参数和模型配置,并能与Claude进行对话。

  • by billster45
  • Python
  • 本地部署
  • 25 星标
  • 更新于
在 GitHub 查看 billster45/mcp-chatgpt-responses

使用说明

MCP ChatGPT服务器

此MCP服务器允许您直接从Claude Desktop访问OpenAI的ChatGPT API。

📝 阅读我为什么构建这个项目: 我构建了一个可以与其他AI对话的AI:揭开MCP炒作的神秘面纱

特性

  • 使用可自定义参数调用ChatGPT API
  • Aks-Claude和ChatGPT进行了长时间的讨论!
  • 配置型号版本、温度和其他参数
  • 使用网络搜索从互联网获取最新信息
  • 使用OpenAI的Responses API进行自动会话状态管理
  • 使用您自己的OpenAI API密钥

安装说明

通过Smithery安装

通过以下方式自动安装Claude Desktop的ChatGPT服务器 史密瑟里:

npx -y @smithery/cli install @billster45/mcp-chatgpt-responses --client claude

先决条件

安装

  1. 克隆此存储库:

    git clone https://github.com/billster45/mcp-chatgpt-responses.git
    cd mcp-chatgpt-responses
    
  2. 使用uv设置虚拟环境并安装依赖项:

    uv venv
    
    .venv\\Scripts\\activate
    
    uv pip install -r requirements.txt
    

与Claude Desktop一起使用

  1. 按照以下说明配置Claude Desktop以使用此MCP服务器: MCP快速入门指南

  2. 将以下配置添加到Claude Desktop配置文件中(根据需要调整路径):

    {
      "mcpServers": {
        "chatgpt": {
          "command": "uv",
          "args": [
            "--directory",
            "\\path\\to\\mcp-chatgpt-responses",
            "run",
            "chatgpt_server.py"
          ],
          "env": {
            "OPENAI_API_KEY": "your-api-key-here",
            "DEFAULT_MODEL": "gpt-4o",
            "DEFAULT_TEMPERATURE": "0.7",
            "MAX_TOKENS": "1000"
          }
        }
      }
    }
    
  3. 重新启动克劳德桌面。

  4. 您现在可以通过Claude使用ChatGPT API,询问提及ChatGPT或Claude可能无法回答的问题。

可用工具

MCP服务器提供以下工具:

  1. ask_chatgpt(prompt, model, temperature, max_output_tokens, response_id) -向ChatGPT发送提示并获得响应

  2. ask_chatgpt_with_web_search(prompt, model, temperature, max_output_tokens, response_id) -在启用web搜索的情况下向ChatGPT发送提示以获取最新信息

示例用法

ChatGPT的基本用法:

告诉克劳德向ChatGPT提问!

Use the ask_chatgpt tool to answer: What is the best way to learn Python?

告诉克劳德与ChatGPT进行对话:

Use the ask_chatgpt tool to have a two way conversation between you and ChatGPT about the topic that is most important to you.

请注意,在轮流进行的会话中,响应id如何允许ChatGPT存储会话的历史记录,使其成为真正的会话,而不仅仅是一系列API调用。这叫做 会话状态.

使用网络搜索:

对于可能受益于最新信息的问题:

Use the ask_chatgpt_with_web_search tool to answer: What are the latest developments in quantum computing?

现在,尝试以代理方式进行网络搜索,根据天气来计划你完美的一天!

Use the ask_chatgpt_with_web_search tool to find the weather tomorrow in New York, then based on that weather and what it returns, keep using the tool to build up a great day out for someone who loves food and parks

运作原理

该工具使用OpenAI的Responses API,该API自动维护OpenAI服务器上的会话状态。这种方法:

  1. 通过让OpenAI处理对话历史来简化代码
  2. 提供更可靠的上下文跟踪
  3. 通过维护消息之间的上下文来改善用户体验
  4. 允许使用网络搜索工具访问网络上的最新信息

许可证

MIT许可证