一个强大的MCP (Model Context Protocol) 服务器,用于自动发送HTTP请求并验证JSON响应。支持多种协议、代理配置和中文错误提示。
- 🚀 自动API请求: 支持GET、POST、PUT、DELETE、PATCH、HEAD、OPTIONS等HTTP方法
- 🌐 多种协议: 支持HTTP和HTTPS协议
- 🛡️ JSON验证: 自动验证响应格式,确保返回有效JSON数据
- 🔄 代理支持: 支持HTTP/HTTPS代理配置
- ⚡ 自动执行: 配置后无需手动确认即可执行API请求
- 🇨🇳 中文界面: 所有错误信息和说明使用中文显示
- 🔧 环境变量: 支持通过环境变量配置代理
- 📊 详细响应: 返回完整的状态码、响应头和数据
git clone https://github.com/your-username/api-request-server.git
cd api-request-servernpm installnpm run build在Cline的配置文件中添加服务器配置:
文件位置: C:\Users\[用户名]\AppData\Roaming\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
配置内容:
{
"mcpServers": {
"api-request-server": {
"autoApprove": [
"send_api_request"
],
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "node",
"args": [
"C:\\path\\to\\api-request-server\\build\\index.js"
],
"env": {
"HTTP_PROXY": "http://127.0.0.1:8080",
"HTTPS_PROXY": "http://127.0.0.1:8080",
"NO_PROXY": "localhost,127.0.0.1,.local"
}
}
}
}重要: 请将 C:\\path\\to\\api-request-server\\build\\index.js 替换为实际的项目路径。
HTTP_PROXY: HTTP请求的代理服务器地址HTTPS_PROXY: HTTPS请求的代理服务器地址NO_PROXY: 不使用代理的主机列表,用逗号分隔
send_api_request({
"url": "https://api.example.com/data"
})send_api_request({
"url": "https://api.example.com/submit",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer your-token"
},
"body": "{\"key\": \"value\"}"
})send_api_request({
"url": "https://api.example.com/data",
"proxy": "http://proxy-server:8080"
})send_api_request({
"url": "https://httpbin.org/post",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"User-Agent": "API-Request-MCP/1.0"
},
"body": "{\"test\": \"data\", \"timestamp\": \"2024-01-01\"}",
"proxy": "http://127.0.0.1:8080"
})| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
url |
string | ✅ | 请求的URL,支持http://和https:// |
method |
string | ❌ | HTTP方法,默认GET。支持:GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS |
headers |
object | ❌ | 请求头对象,键值对形式 |
body |
string | ❌ | 请求体内容,POST等方法使用 |
proxy |
string | ❌ | 代理服务器地址,格式:http://host:port |
成功响应格式:
{
"status": 200,
"statusText": "OK",
"headers": {
"content-type": "application/json",
"server": "nginx"
},
"data": {
"key": "value"
}
}错误响应格式:
{
"content": [
{
"type": "text",
"text": "请求失败: 错误信息"
}
],
"isError": true
}- 最高优先级: 通过
proxy参数直接指定 - 中等优先级: 环境变量配置 (HTTP_PROXY, HTTPS_PROXY)
- 最低优先级: 如果URL在NO_PROXY列表中,不使用代理
默认超时时间为30秒,如需修改可在代码中调整:
timeout: 30000, // 30秒A: 这是Cline的UI限制。配置文件中正确设置后,工具会自动执行,无需手动确认。
A: 有两种方式:
- 在MCP配置的env中设置HTTP_PROXY和HTTPS_PROXY
- 在API调用时通过proxy参数指定
A: 目前支持HTTP和HTTPS代理。SOCKS代理暂不支持。
A: 工具会自动尝试解析JSON。如果响应不是有效JSON,会返回错误信息和原始响应内容。
A: 在代码的axios配置中修改timeout参数,默认为30秒。
api-request-server/
├── src/
│ └── index.ts # 主服务器文件
├── build/ # 编译输出目录
├── package.json # 项目配置
├── tsconfig.json # TypeScript配置
└── README.md # 说明文档
# 安装依赖
npm install
# 开发构建
npm run build
# 启动服务器测试
npm start- Node.js: 运行环境
- TypeScript: 类型安全的开发
- Axios: HTTP请求库
- @modelcontextprotocol/sdk: MCP协议实现
MIT License - 详见LICENSE文件
欢迎提交Issue和Pull Request!
如果遇到问题,请:
- 检查配置文件路径是否正确
- 确认build目录下的index.js文件存在
- 查看Cline的输出日志
- 提交GitHub Issue
最后更新: 2025年12月3日