api2mcp
Serves any OpenAPI 3.x/Swagger 2.x API as a local MCP server over stdio, converting every operation into a tool that proxies requests to the upstream API with configurable headers and fixed parameters.
README
@swayam5342/api2mcp
Serve any OpenAPI 3.x / Swagger 2.x API as a local MCP (Model Context Protocol) server over stdio. Every operation in the spec becomes an MCP tool; when a tool is called, the request is proxied to the real upstream HTTP API with your configured auth.
It does exactly two things:
- Serve — given a spec (file path or URL), run an MCP server on stdio so Claude Desktop, Claude Code, and other MCP clients can launch it as a subprocess. One spec → one server.
- Proxy — forward tool calls to the upstream API using the method/path/params from the spec, injecting your configured headers and fixed params, and return the response.
No telemetry, no database, no eval. The only network egress is the upstream calls you configure (plus fetching the spec itself if you pass a URL).
Quick start
npx @swayam5342/api2mcp --url https://petstore3.swagger.io/api/v3/openapi.json
That's a running MCP server on stdio — every Petstore endpoint is now a tool. Point an MCP client at it (see below) and ask it to list pets.
Install
# no install needed
npx @swayam5342/api2mcp --url ./openapi.json
# or globally
npm install -g @swayam5342/api2mcp
api2mcp --url ./openapi.json
Requires Node.js >= 18.
Use with Claude Desktop
Add to your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"petstore": {
"command": "npx",
"args": [
"-y",
"@swayam5342/api2mcp",
"--url",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
}
}
}
Restart Claude Desktop; the spec's operations appear as tools named after their operationId (e.g. addPet, getPetById).
CLI reference
api2mcp --url <spec> [options]
| Flag | Short | Description |
|---|---|---|
--url <url> |
-u |
OpenAPI/Swagger spec — file path or URL |
--base-url <url> |
-b |
Upstream base URL (overrides the spec's servers / host+basePath) |
--headers <json> |
— | Upstream headers as a JSON object string |
--prefix <prefix> |
-p |
Prefix for generated tool names (myapi_listPets) |
--timeout <ms> |
-t |
Upstream request timeout in ms (default 30000) |
--fixed-params <params> |
-f |
Params injected into every upstream request, hidden from the LLM (key=value pairs or JSON) |
--debug |
-d |
Verbose logging to stderr (secrets redacted) |
--headers intentionally has no short flag: -h shows help.
Configuration
Every flag can also come from environment variables or a config file. Precedence: CLI flags > environment variables > config file.
Environment variables
| Variable | Meaning |
|---|---|
OPENAPI_URL |
Spec file path or URL |
API_BASE_URL |
Upstream base URL |
API_TIMEOUT |
Timeout in ms |
API_HEADERS |
Headers as a JSON object string |
API_FIXED_PARAMS |
Fixed params (key=value or JSON) |
DEBUG |
Debug logging (0/false/off disable) |
Config file
The first of api2mcp.json, api2mcp.config.json, .api2mcp.json found in the working directory is used:
{
"url": "https://api.example.com/openapi.json",
"baseUrl": "https://api.example.com",
"timeout": 30000,
"headers": { "Authorization": "Bearer your-token" },
"fixedParams": { "apiKey": "your-key" },
"toolPrefix": "myapi"
}
Passing secrets safely
Don't put API keys in --headers or --fixed-params on the command line — process arguments are visible to other users on the machine (ps). Use your MCP client's env field instead:
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": ["-y", "@swayam5342/api2mcp", "--url", "https://api.example.com/openapi.json"],
"env": {
"API_HEADERS": "{\"Authorization\":\"Bearer YOUR_TOKEN\"}",
"API_FIXED_PARAMS": "apiKey=YOUR_KEY"
}
}
}
}
All header and fixed-param values are redacted (***) from every log line and error message, including upstream error bodies that echo them back.
Fixed params: auth the LLM never sees
Fixed params are injected into every upstream request but are stripped from the tool schemas, so the model never sees the key and cannot leak or misuse it:
API_FIXED_PARAMS="apiKey=YOUR_KEY" npx @swayam5342/api2mcp --url ./openapi.json
- If the spec declares a matching parameter (query, or a body property), the value is injected in that declared location.
- Unknown keys are sent as query parameters.
- Accepts
key=value, comma-separateda=1,b=2, or a JSON object string.
How operations become tools
| Spec | Tool |
|---|---|
operationId: listPets |
tool listPets (with --prefix pets: pets_listPets) |
no operationId, GET /pets/{petId} |
tool get_pets_petId |
summary / description |
tool description (fallback: GET /pets) |
| path/query/header params | top-level input fields, required per the spec |
| JSON request body (object) | properties flattened into top-level input fields |
| JSON request body (non-object) | single body input field |
v1 limitations: JSON request bodies only (no multipart/form-urlencoded), cookie params ignored, and every operation is registered directly (no on-demand mode for very large specs).
Worked example: Petstore
npx @swayam5342/api2mcp --url https://petstore3.swagger.io/api/v3/openapi.json --prefix pets --debug
stderr shows the redacted config and registered N tools ..., then the server waits on stdio. In Claude Desktop:
{
"mcpServers": {
"petstore": {
"command": "npx",
"args": [
"-y",
"@swayam5342/api2mcp",
"--url", "https://petstore3.swagger.io/api/v3/openapi.json",
"--prefix", "pets"
]
}
}
}
Then ask Claude: "Find available pets in the store" — it calls pets_findPetsByStatus with status: "available", the call is proxied to https://petstore3.swagger.io/api/v3/pet/findByStatus?status=available, and the JSON response comes back as the tool result.
Library API
import { createServer, resolveConfig } from "@swayam5342/api2mcp";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const config = await resolveConfig({ url: "./openapi.json" }); // merges env + config file
const server = await createServer(config); // an SDK McpServer, tools registered
await server.connect(new StdioServerTransport()); // or any other transport
Exports: createServer(config, options?), resolveConfig(cliFlags, options?), and the types Api2McpConfig, CreateServerOptions. options.fetchImpl lets you swap the HTTP layer (e.g. for tests).
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。