API测试仪MCP服务器
这是一个模型上下文协议(MCP)服务器,允许Claude代表您提出API请求。它提供了测试各种API的工具,包括与OpenAI API的专用集成。
特性
- 向任何API发出HTTP请求(GET、POST、PUT、DELETE)
- 测试OpenAI的GPT模型,而无需在聊天中共享您的API密钥
- 使用 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 Desktop配置文件中配置它来将其连接到Claude for Desktop。
示例提示
API通用测试
Use the get_request tool to fetch data from https://jsonplaceholder.typicode.com/posts/1Use 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密钥
