OpenAPI MCP服务器
一个模型上下文协议(MCP)服务器,使LLM能够通过结构化工具探索和理解OpenAPI规范。
特性
- 🔍 API智能勘探 -按类别、端点和模式导航API
- 🚀 多种模式 -以stdio(用于Claude Desktop)、HTTP服务器或交互式CLI运行
- 💾 智能高速缓存 -缓存远程OpenAPI规范,以实现更快的访问
- 🏗️ 多架构 -支持Linux AMD64和ARM64
快速开始
使用克劳德桌面
添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json 在 macOS 上:
{
"mcpServers": {
"openapi": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "OPENAPI_SPEC_URL=https://api.example.com/openapi.json", "ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:latest"]
}
}
}或者使用本地二进制文件:
{
"mcpServers": {
"openapi": {
"command": "/path/to/openapi-mcp-stdio",
"env": {
"OPENAPI_SPEC_URL": "https://api.example.com/openapi.json"
}
}
}
}安装
Docker(推荐)
# Latest (stdio mode)
docker pull ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:latest
# Specific modes
docker pull ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:http
docker pull ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:interactive下载二进制文件
下载自 发布:
openapi-mcp-stdio-linux-amd64-MCP标准模式openapi-mcp-http-linux-amd64-HTTP服务器模式openapi-mcp-interactive-linux-amd64-交互式CLI模式
从源代码构建
# Clone
git clone https://github.com/SagenKoder/go-openapi-exploration-mcp-server.git
cd go-openapi-exploration-mcp-server
# Build all modes
./build.sh
# Or build specific mode
go build -o openapi-mcp-stdio ./cmd/openapi-mcp-stdio用法
环境变量
OPENAPI_SPEC_URL(必填)-OpenAPI规范的URL或文件路径OPENAPI_CACHE_DIR(可选)-缓存目录(默认:~/.openapi-mcp-cache)
标准模式(适用于MCP客户端)
# Docker
docker run -i --rm \
-e OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json \
ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:latest
# Binary
OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json ./openapi-mcp-stdioHTTP模式
# Docker
docker run -p 8080:8080 \
-e OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json \
ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:http
# Binary
OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json ./openapi-mcp-http -addr :8080交互模式
# Docker
docker run -it --rm \
-e OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json \
ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:interactive
# Binary
OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json ./openapi-mcp-interactive可用工具
服务器为LLM提供以下工具:
- 列表_类别 -根据路径段列出API类别
- list_endpoints -列出端点,可选择按类别筛选
- show_endpoint -显示详细的端点信息,包括参数和模式
- get_spec_info -获取有关API的一般信息
- show_schema -检查特定的架构组件
例子
本地文件
OPENAPI_SPEC_URL=/path/to/openapi.yaml ./openapi-mcp-stdio使用自定义缓存
OPENAPI_CACHE_DIR=/tmp/api-cache \
OPENAPI_SPEC_URL=https://api.example.com/openapi.json \
./openapi-mcp-stdio带卷挂载的Docker
docker run -i --rm \
-v $(pwd)/openapi.yaml:/openapi.yaml:ro \
-e OPENAPI_SPEC_URL=/openapi.yaml \
ghcr.io/sagenkoder/go-openapi-exploration-mcp-server:latest发展
项目结构
cmd/
├── openapi-mcp-stdio/ # MCP stdio mode
├── openapi-mcp-http/ # HTTP server mode
└── openapi-mcp-interactive/ # Interactive CLI mode
internal/
├── cache.go # Caching logic
├── handlers.go # MCP tool handlers
├── server.go # Core server logic
└── utils.go # Utilities构建Docker镜像
# Build specific mode
docker build --build-arg MODE=stdio -t my-openapi-mcp:stdio .
# Build all modes
./build.sh docker许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
