API包装服务器

一个通用的API包装服务器,用于将REST API包装为MCP工具,供Claude和其他MCP客户端访问。

  • by gomcpgo
  • Go
  • 本地部署
  • 20 星标
  • 更新于
在 GitHub 查看 gomcpgo/api-wrapper-mcp

使用说明

API包装器MCP服务器

这是用于模型上下文协议(MCP)的通用API包装服务器。它允许您轻松地将REST API包装为可由Claude和其他MCP客户端访问的MCP工具。

特性

  • 为多个API端点轻松配置YAML
  • 同时支持GET和POST请求
  • 参数验证和默认值
  • 通过环境变量进行身份验证
  • API调用的自定义超时

用法

  1. 创建一个定义API端点的YAML配置文件(请参阅 example-config.yaml)
  2. 将任何必需的API令牌设置为环境变量
  3. 使用您的配置文件运行服务器:
# Build the server
go build -o api_wrapper

# Run with your config
./api_wrapper my-apis.yaml

配置格式

配置文件使用具有以下结构的YAML格式:

# Server info
server:
  name: "API Gateway MCP"
  description: "Generic API gateway that wraps REST APIs as MCP tools"
  version: "1.0.0"
  
# Authentication
auth:
  token_env_var: "API_GATEWAY_TOKEN"  # Environment variable for the API token

# Tool definitions
tools:
  - name: "tool-name"
    description: "Tool description"
    endpoint: "https://api.example.com/endpoint"
    method: "POST"  # or "GET"
    timeout: 30  # in seconds
    template: |
      {
        "param1": "{{variable1}}",
        "param2": {{variable2}}
      }
    # For GET requests, use query_params
    query_params:
      param1: "{{variable1}}"
      param2: "{{variable2}}"
    parameters:
      variable1:
        type: "string"
        description: "Description of variable1"
        required: true
      variable2:
        type: "number"
        description: "Description of variable2"
        default: 10

Claude桌面集成

要与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}} 语法。