api2mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
api2mcp
把任意 OpenAPI 3.x 服务变成 AI 智能体能调用的 MCP Server。
你有一个 REST API、一份 Swagger 文档,想让 Cursor / Claude Code / WorkBuddy 里的智能体直接调用它——不用手写一个工具函数,指向那份 OpenAPI 定义就行。
零依赖 Node.js 18+,单文件运行。当前版本 v0.2.0。
v0.2 新增了"接真实系统"必需的能力:环境变量密钥注入(不落盘)、5xx/429 指数退避重试、结构化错误解析、OpenAPI 3.1 / Pydantic anyOf 完整支持、鉴权方案自动提示。
30 秒试用
# 列出从 OpenAPI 定义生成了哪些工具
node server.js --spec examples/petstore.openapi.json --tools
# 以 MCP Server 模式启动(默认只暴露只读 GET 工具)
node server.js --spec examples/petstore.openapi.json \
--base-url https://petstore3.swagger.io/api/v3第一个命令会真实输出 8 个工具:
findpetsbystatus GET /pet/findByStatus Finds Pets by status.
getpetbyid GET /pet/{petId} Find pet by ID.
getinventory GET /store/inventory Returns pet inventories by status.
...Related MCP server: OMCP
接入自有系统
任何有 OpenAPI 定义的服务都能接。以一个 FastAPI 服务(voicebox,22 个操作)为例:
node server.js \
--spec /path/to/your-service/openapi.json \
--base-url http://127.0.0.1:8000 \
--allow-write \
--secret "Authorization=Bearer $TOKEN"下面的工具名和验证结果来自一次真实接入(见 案例);把
--spec换成你自己的 OpenAPI 定义即可。
生成后的工具名简洁可用:
list_profiles GET /profiles
create_profile POST /profiles
generate_speech POST /generate
transcribe_audio POST /transcribe如果你的项目是 FastAPI 自动生成的 operationId(如 list_profiles_profiles_get),工具会自动简化为 list_profiles。
安全设计
行为 | 默认 |
GET / HEAD / OPTIONS | 暴露 |
POST / PUT / DELETE / PATCH | 不暴露,需显式 |
HTTP 超时 | 15 秒,可 |
失败重试 | 5xx/429 指数退避,默认 0 次,可 |
错误反馈 | 上游错误体结构化解析( |
鉴权头 | 推荐 |
stdout | 仅 JSON-RPC 消息,日志走 stderr |
写操作默认关闭是刻意的:让智能体动手改数据之前,人要先明确授权一次。
密钥安全:用 --secret 而不是 --header
--header 适合非敏感头;密钥务必用 --secret,值从环境变量读取,不出现在命令行历史、不写进生成物:
# 方式一:完整值来自环境变量
export API_TOKEN="xxx"
node server.js --spec ./openapi.json --secret "Authorization=Bearer $API_TOKEN"
# 方式二:带前缀拼接
node server.js --spec ./openapi.json --secret "X-API-Key=$API_KEY"API 定义了 securitySchemes 时,--tools 会自动列出该配哪种鉴权及对应命令。
失败重试
真实 API 会抖动。开启重试后,5xx / 429 / 408 及网络错误会自动指数退避重试,429 还会遵守 Retry-After 响应头:
node server.js --spec ./openapi.json --retry 3 --retry-delay 500返回结果里的 attempts 字段显示实际请求次数,4xx 不会重试。
参数
参数 | 说明 |
| OpenAPI 3.x JSON 文件路径(必填) |
| API 根地址;spec 里有绝对 server url 时可省略 |
| Server 名称,默认取 |
| 注入请求头,可重复 |
| 允许生成写操作工具 |
| HTTP 超时,默认 15000 |
| 从环境变量读取密钥注入请求头(不落盘) |
| 5xx/429 重试次数,默认 0 |
| 重试初始退避,默认 500 |
| stderr 输出每次请求(不打印密钥) |
| 列出将生成的工具后退出(验收用) |
| 生成独立可运行的 server 到指定目录 |
$ref 与请求体
自动解析
#/components/schemas/...引用和allOf组合。JSON 请求体的字段会展开成独立参数,并标注
required,智能体能直接填。path 参数替换、query 拼接、body 序列化都按 OpenAPI 规范处理。
生成独立 Server
node server.js --spec ./openapi.json --base-url https://api.example.com --emit ./my-mcp
cd my-mcp && node server.js生成目录包含 server.js、api2mcp.config.json、README.md。改 API 地址或鉴权头直接编辑配置文件即可。
接入编辑器
把生成的服务配置到客户端 MCP 配置:
{
"mcpServers": {
"my-api": {
"command": "node",
"args": ["/absolute/path/to/api2mcp/server.js",
"--spec", "/absolute/path/to/openapi.json",
"--base-url", "https://api.example.com"]
}
}
}随后在对话里说"用 my-api 查一下……"即可。
验证
node test/smoke.js覆盖:真实 MCP 协议握手、只读安全约束、path/query/body 参数映射、自定义请求头、HTTP 转发、Petstore 真实规范、--emit 自举、voicebox 22 个操作接入、5xx/429 重试、错误体解析、--secret 环境变量注入、3.1 nullable / Pydantic anyOf、鉴权提示、生成物密钥不落盘。HTTP 全部走本地 mock,不依赖外网。
当前基线:18/18 PASS。
另有 voicebox 接入案例专项验证:
node test/voicebox-case.js6/6 PASS——对 --emit 生成的独立 server 走完整 MCP 调用。完整案例见 docs/VOICEBOX_CASE.md。
许可
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Host any HTTP API as a standard MCP server; auto-distribute to 12+ mainstream agent platforms.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
MCP server that lets AI assistants use all OneSchema features exposed via the public API.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAutomatically converts any OpenAPI specification into an MCP server, exposing all HTTP endpoints as callable tools with support for various authentication methods and request types.2-
- AlicenseNot gradedqualityDmaintenanceConverts an OpenAPI spec into an MCP server, enabling AI agents to call your API without writing tool definitions or integration code.3MIT
- AlicenseNot gradedqualityCmaintenanceConverts any OpenAPI 3.x spec into a live MCP server, making every endpoint a validated tool that AI agents can call without writing glue code.12 npmMIT
- AlicenseNot gradedqualityCmaintenanceTurns any OpenAPI 3.x spec into an MCP server that exposes one validated tool per API operation, so AI agents can discover and call a REST API over stdio or Streamable HTTP. It is read-only by default, with allow/deny lists, environment-based auth, timeouts and response truncation for safe agent access.MIT