Information
API 测试器 MCP 服务器
这是一个模型上下文协议(MCP)服务器,允许 Claude 代表您发出 API 请求。它提供了测试各种 API 的工具,包括与 OpenAI 的 API 的专用集成。
特性
向任何 API 发出 HTTP 请求(GET、POST、PUT、DELETE)
在不分享您的 API 密钥的情况下测试 OpenAI 的 GPT 模型
使用 DALL-E 生成图像
妥善格式化的响应以便于阅读
设置
先决条件
Python 3.10 或更高版本
MCP SDK 1.2.0 或更高版本
安装
安装所需的依赖项:
pip install "mcp[cli]" httpx python-dotenv
使用以下方法之一设置您的 OpenAI API 密钥:
选项 1:环境变量
# On Windows (PowerShell)
$env:OPENAI_API_KEY = "your-api-key"
# On Windows (Command Prompt)
set OPENAI_API_KEY=your-api-key
# On macOS/Linux
export OPENAI_API_KEY="your-api-key"
选项 2:使用 .env 文件(推荐)
在项目目录中创建一个 .env 文件(从 .env.example 复制):
OPENAI_API_KEY=your_openai_api_key_here
运行服务器
python main.py
与 Claude 一起使用
一旦您的服务器运行起来,您可以通过在 Claude Desktop 配置文件中进行配置来将其连接到 Claude for Desktop。
示例提示
通用 API 测试
Use the get_request tool to fetch data from https://jsonplaceholder.typicode.com/posts/1
Use the post_request tool to send data to https://jsonplaceholder.typicode.com/posts with this JSON body: \{"title": "Test Post", "body": "This is a test", "userId": 1\}
使用 OpenAI 工具
Use the openai_chat_completion tool with:
prompt: "Write a short poem about artificial intelligence"
system_message: "You are a helpful assistant that writes creative poetry"
model: "gpt-4"
Use the openai_image_generation tool with:
prompt: "A futuristic city with flying cars and tall glass buildings at sunset"
size: "1024x1024"
可用工具
通用 API 工具
get_request: 向任何 URL 发送 GET 请求
post_request: 使用 JSON 主体发送 POST 请求
put_request: 使用 JSON 主体发送 PUT 请求
delete_request: 发送 DELETE 请求
OpenAI 特定工具
openai_chat_completion: 使用 OpenAI 的聊天模型生成文本
openai_image_generation: 使用 DALL-E 生成图像
安全须知
您的 OpenAI API 密钥存储在服务器中,不会在聊天中暴露
API 使用将计入您的 OpenAI 配额,并可能产生费用
对于生产用途,请始终将 API 密钥设置为环境变量或使用 .env 文件
.env 文件包含在 .gitignore 中,以防止意外提交您的 API 密钥