这是一个用于模型上下文协议(MCP)的通用 API 包装器服务器。它允许您轻松地将 REST API 包装成可以被 Claude 和其他 MCP 客户端访问的 MCP 工具。
example-config.yaml)# 构建服务器
go build -o api_wrapper
# 使用您的配置运行
./api_wrapper my-apis.yaml
配置文件使用 YAML 格式,具有以下结构:
# 服务器信息
server:
name: "API Gateway MCP"
description: "通用 API 网关,将 REST API 包装成 MCP 工具"
version: "1.0.0"
# 身份验证
auth:
token_env_var: "API_GATEWAY_TOKEN" # API 令牌的环境变量
# 工具定义
tools:
- name: "tool-name"
description: "工具描述"
endpoint: "https://api.example.com/endpoint"
method: "POST" # 或 "GET"
timeout: 30 # 单位:秒
template: |
{
"param1": "{{variable1}}",
"param2": {{variable2}}
}
# 对于 GET 请求,使用 query_params
query_params:
param1: "{{variable1}}"
param2: "{{variable2}}"
parameters:
variable1:
type: "string"
description: "variable1 的描述"
required: true
variable2:
type: "number"
description: "variable2 的描述"
default: 10
要与 Claude Desktop 集成,请在您的 claude_desktop_config.json 中添加以下内容:
{
"mcpServers": {
"api-wrapper": {
"command": "path/to/api_wrapper",
"args": ["path/to/your-config.yaml"],
"env": {
"API_GATEWAY_TOKEN": "your-api-token"
}
}
}
}
查看 example-config.yaml 获取示例 API 配置。
auth.token_env_var 字段中指定的环境变量设置主要认证令牌。{{env:VARIABLE_NAME}} 语法引用其他环境变量。