内容
# Meta API MCP Server
一个与模型上下文协议(MCP)一起使用的meta API网关服务器。您可以通过MCP将任何API连接到LLM(Claude、GPT等)。这使AI助手能够直接与API交互并访问真实世界的数据源。
## 功能
- 🔄 多API支持:通过单个服务器管理多个API
- 🛠️ 使用JSON配置文件轻松添加API
- 📋 自动将Postman Collections转换为MCP工具
- 🔌 全面支持HTTP APIs (GET, POST, PUT, DELETE, PATCH)
- 🔒 多种身份验证方法(API Key,Bearer Token)
- 📁 从本地文件或远程URL加载配置
- 📑 支持配置文件列表
## API Editor Tool
已开发了一个用户友好的编辑器工具来创建或编辑JSON配置文件:
[MCP API Editor](https://savhascelik.github.io/mcp-api-editor/)
## 安装
### 使用NPM全局安装(推荐)
```bash
npm install -g meta-api-mcp-server
```
### 从源代码安装
```bash
git clone https://github.com/savhascelik/meta-api-mcp-server.git
cd meta-api-mcp-server
npm install
```
## 使用方法
### 作为命令行工具
```bash
# 从默认的api-configs/文件夹加载
meta-api-mcp-server
# 指定一个配置文件(在您运行服务器的目录中,应该有一个具有此名称的文件夹,并且其中包含结构化的json)
meta-api-mcp-server path/to/config.json
# 从特定文件夹加载
meta-api-mcp-server path/to/configs/
# 从远程URL加载
meta-api-mcp-server https://example.com/api-config.json
# 从远程配置列表加载
meta-api-mcp-server https://example.com/config-list.json
# 从Postman Collection加载(您的文件名必须包含单词“postman”,我会在有时间时将其绑定到一个变量)
meta-api-mcp-server path/to/My-API.postman_collection.json
```
### 与Cursor或其他MCP客户端一起使用
要连接到像Cursor这样的MCP客户端,请按如下方式配置您的`mcp.json`文件:
```json
{
"mcpServers": {
"myApiServer": {
"command": "meta-api-mcp-server",
"args": [
],
"env": {
"MCP_CONFIG_SOURCE":"api-configs/flexweather-endpoints.json",
"API_KEY": "your-api-key-here"
}
}
}
}
```
```json
{
"mcpServers": {
"myApiServer": {
"command": "meta-api-mcp-server",
"args": [
"server.js",
"path/to/api-config.json"
],
"env": {
"EXAMPLE_API_KEY": "your-api-key-here"
}
}
}
}
```
```json
{
"mcpServers": {
"flexweather": {
"command": "node",
"args": [
"server.js"
],
"env": {
"MCP_CONFIG_SOURCE":"api-configs/flexweather-endpoints.json"
}
}
}
}
```
```json
{
"mcpServers": {
"lemonsqueezy": {
"command": "node",
"args": [
"server.js"
],
"env": {
"MCP_CONFIG_SOURCE":"api-configs/lemon-squeezy-api.json",
"LEMON_SQUEEZY_API_KEY": ""
}
}
}
}
```
## Postman Collection转换
现在可以非常轻松地将您现有的Postman collections与Meta API MCP Server一起使用!您可以使用数百个现成的API,而无需编写任何代码。
1. 导出您的Postman collection(采用v2.1.0格式)
2. 使用collection文件启动Meta API MCP Server:
```bash
meta-mcp my-collection.postman_collection.json
```
3. 服务器将自动执行以下操作:
- 分析所有端点
- 检测身份验证方法
- 提取路径/查询参数
- 分析请求正文结构
- 创建MCP工具
4. 将您的API Key添加到`.env`文件(服务器会告诉您要使用哪个环境变量)
### 支持的Postman Collection功能
- ✅ 多级文件夹结构
- ✅ Bearer Token身份验证
- ✅ API Key身份验证
- ✅ 路径参数
- ✅ 查询参数
- ✅ 标头
- ✅ JSON请求正文
- ✅ Postman变量(如{{api_url}})
## API Editor Tool
已开发了一个用户友好的编辑器工具来创建或编辑JSON配置文件:
[MCP API Editor](https://savhascelik.github.io/mcp-api-editor/)
使用此Web工具,您可以:
- 通过可视化界面创建API配置
- 编辑现有的JSON配置
- 将Postman collections转换为MCP兼容的配置文件
- 验证配置文件
- 将您的配置导出为JSON
**Postman Collections:**您可以将现有的Postman collections上传到编辑器工具,并自动将其转换为MCP兼容的配置。这使您可以快速使用现有的collections,而无需从头开始配置API。
该编辑器使您可以轻松管理工具名称、参数和所有其他配置选项。
## 项目结构
代码库以模块化的方式组织,以方便维护和扩展:
```
meta-api-mcp-server/
├── serve.js
├── api-configs/ # 默认配置目录
└── package.json
```
## API配置文件格式
您可以使用以下JSON格式手动配置API:
```json
{
"apiId": "my-api",
"handlerType": "httpApi",
"baseUrl": "https://api.example.com",
"authentication": {
"type": "bearerToken",
"envVariable": "MY_API_TOKEN"
},
"endpoints": [
{
"mcpOperationId": "getUsers",
"description": "Get a list of users",
"targetPath": "/users",
"targetMethod": "GET",
"parameters": [
{
"name": "page",
"in": "query",
"required": false,
"type": "integer",
"description": "Page number"
}
]
}
]
}
```
## 许可证
MIT