REST API MCP服务器
用于REST和GraphQL API的通用MCP服务器 -只有两个简单的工具可以处理一切:所有HTTP方法、文件上传/下载和内容类型的自动检测。
为什么选择此服务器?
之前(v1.2): 9个令人困惑的工具- rest_api_get, rest_api_post, rest_api_put, rest_api_patch, rest_api_delete, rest_api_upload_file, rest_api_download_file, rest_api_form_urlencoded, rest_api_graphql
现在(v1.3): 只有两个智能工具:
rest_api_request-处理所有REST API操作rest_api_graphql-处理GraphQL查询/突变
不用再为使用哪个工具而困惑了!
特性
- 通用工具:一个用于所有HTTP方法(GET、POST、PUT、PATCH、DELETE)的工具
- 智能自动检测:自动检测JSON、表单url编码或多部分文件上传
- 文件上传:通过多部分/表单数据上传图像、文档
- 文件下载:自动保存二进制响应(图像、PDF等)
- 所有身份验证类型:API密钥、承载令牌、基本身份验证
- 重试逻辑:网络错误的自动指数回退
- 图查询语言:完全支持查询、突变、变量
- 固定拥抱脸:现在可以使用图像生成API(接受: */*)
安装
npm install -g rest-api-mcp-server或本地:
npm install rest-api-mcp-server配置
添加到您的MCP设置中(例如,Claude Desktop配置):
{
"mcpServers": {
"rest-api": {
"command": "rest-api-mcp-server"
}
}
}2工具
1. rest_api_request -通用REST API工具
手柄 一切:GET、POST、PUT、PATCH、DELETE、文件上传、文件下载、表单提交。
关键参数:
url(必填):完整URLmethod(可选):GET、POST、PUT、PATCH、DELETE(默认值:GET)body(可选):请求正文(自动检测JSON/form/multipart)saveResponseTo(可选):保存二进制响应的文件路径contentType(可选):覆盖自动检测headers,queryParams,timeout:标准选项- 认证:
authType,bearerToken,apiKey,username,password
示例:
简单GET:
{
"url": "https://api.example.com/users",
"method": "GET"
}发布JSON:
{
"url": "https://api.example.com/users",
"method": "POST",
"body": {
"name": "John Doe",
"email": "john@example.com"
},
"bearerToken": "your-token"
}上传文件:
{
"url": "https://api.example.com/upload",
"method": "POST",
"body": {
"files": [
{
"path": "C:\\Users\\Name\\image.jpg",
"fieldName": "file",
"mimeType": "image/jpeg"
}
]
},
"bearerToken": "your-token"
}下载图片(例如,拥抱脸):
{
"url": "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev",
"method": "POST",
"body": {
"inputs": "A cat in a sunbeam"
},
"saveResponseTo": "C:\\Users\\Name\\generated_cat.png",
"bearerToken": "hf_xxxxx",
"timeout": 60000
}表单提交(OAuth):
{
"url": "https://oauth.example.com/token",
"method": "POST",
"body": {
"grant_type": "client_credentials",
"client_id": "xxx",
"client_secret": "yyy"
},
"contentType": "application/x-www-form-urlencoded"
}2. rest_api_graphql -GraphQL工具
执行GraphQL查询和突变。
关键参数:
url(必填):GraphQL端点query(必填):GraphQL查询/变异字符串variables(可选):变量对象operationName(可选):操作名称httpMethod(可选):GET或POST(默认:POST)- 认证:与rest_api_request相同
例子:
{
"url": "https://api.example.com/graphql",
"query": "query GetUser($id: ID!) { user(id: $id) { name email } }",
"variables": {
"id": "123"
},
"bearerToken": "your-token"
}v1.3有什么变化?
整合
- 远离的:
rest_api_get,rest_api_post,rest_api_put,rest_api_patch,rest_api_delete - 远离的:
rest_api_upload_file,rest_api_download_file,rest_api_form_urlencoded - 新增:单
rest_api_request这就够了
修复
- 固定的
Accept: */*header(现在可用于Hugging Face图像生成) - 自动从正文结构中检测内容类型
- 自动保存二进制响应
saveResponseTo提供
对于AI模型
更清楚了!不再混淆:
- 何时使用
rest_api_get对比rest_api_download_file - 何时使用
rest_api_post对比rest_api_upload_file对比rest_api_form_urlencoded
现在:只需使用 rest_api_request 使用适当的参数!
测试
npm test示例用例
- 获取API数据:带身份验证的简单GET
- 创建资源:带有JSON正文的POST
- 更新资源:使用JSON进行PUT/PATCH
- 删除资源:使用身份验证删除
- 上传文件:带有多部分的POST(自动检测)
- 下载文件:任何方法+
saveResponseTo - OAuth令牌:POST表单url编码(自动检测)
- GraphQL API:带有变量的查询和突变
- AI 图像生成:拥抱面部、复制等。
许可证
麻省理工学院
贡献
欢迎在
版本历史
- v1.3.0版本将9个工具合并为2个;修复了Accept标头;自动检测
- v1.2.0版本:添加了GraphQL支持
- v1.1.0版本:添加了文件上传/下载、表单url编码、重试逻辑
- v1.0.0:具有基本REST方法的初始版本
