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
Your API, as tools Claude can call.
@swayam5342/api2mcp serves any OpenAPI 3.x / Swagger 2.x API as a local MCP (Model Context Protocol) server over stdio, written in TypeScript. Every operation in the spec becomes an MCP tool; when a tool is called, the request is proxied to the real upstream API with your configured auth, which the model never sees.
Website · Quick Start · CLI Reference · Passing Secrets Safely · Library API
Table of Contents
Overview | How It Works · How Operations Become Tools |
Setup | Prerequisites · Quick Start · Install · Use with Claude Desktop · Use with Claude Code |
Reference | CLI Reference · Configuration · Library API |
Security | Passing Secrets Safely · Fixed Params: Auth the LLM Never Sees |
Examples |
Related MCP server: openapi-mcp
How It Works
It does exactly two things:
Step | What happens | |
1 | 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. |
2 | Proxy | Forward tool calls to the upstream API using the method, path and params from the spec, inject 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.
Prerequisites
Requirement | When |
Node.js 18+ | Always ( |
An OpenAPI 3.x or Swagger 2.x spec | A file path or a URL. |
pnpm | Only to build from source. |
Quick Start
npx @swayam5342/api2mcp --url https://petstore3.swagger.io/api/v3/openapi.jsonThat's a running MCP server on stdio: every Petstore endpoint is now a tool. Point an MCP client at it (below) and ask it to list pets.
Install
npx @swayam5342/api2mcp --url ./openapi.jsonnpm install -g @swayam5342/api2mcp
api2mcp --url ./openapi.jsonUse with Claude Desktop
Add this to your Claude Desktop config file:
OS | Config file |
macOS |
|
Windows |
|
{
"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 (for example addPet, getPetById).
Use with Claude Code
claude mcp add petstore -- npx -y @swayam5342/api2mcp --url https://petstore3.swagger.io/api/v3/openapi.jsonPass secrets with-e, not as arguments: claude mcp add my-api -e API_HEADERS='{"Authorization":"Bearer YOUR_TOKEN"}' -- npx -y @swayam5342/api2mcp --url https://api.example.com/openapi.json
CLI Reference
api2mcp --url <spec> [options]Flag | Short | Description |
|
| OpenAPI/Swagger spec: file path or URL. |
|
| Upstream base URL (overrides the spec's |
| none | Upstream headers as a JSON object string. |
|
| Prefix for generated tool names ( |
|
| Upstream request timeout in ms (default |
|
| Params injected into every upstream request, hidden from the LLM ( |
|
| 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.
Variable | Meaning |
| Spec file path or URL. |
| Upstream base URL. |
| Timeout in ms. |
| Headers as a JSON object string. |
| Fixed params ( |
| Debug logging ( |
The first of api2mcp.json, api2mcp.config.json or .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.jsonCase | Where the value goes |
The spec declares a matching parameter (query, or a body property) | Injected in that declared location. |
The key isn't declared | Sent as a query parameter. |
Accepts key=value, comma-separated a=1,b=2, or a JSON object string.
How Operations Become Tools
Spec | Tool |
| Tool |
No operationId, | Tool |
| Tool description (fallback: |
Path, query and 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) | A single |
v1 limitations: JSON request bodies only (no multipart or form-urlencoded), cookie params are 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 --debugstderr shows the redacted config and registered N tools ..., then the server waits on stdio.
{
"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 transportExport | What it is |
| Builds an MCP SDK |
| Merges CLI flags, environment variables and the config file, in that precedence. |
| Types. |
Verification & Testing
pnpm install
pnpm typecheck
pnpm build
pnpm testThe same four steps run in GitHub Actions on every push and pull request to master (.github/workflows/ci.yml). Tests use the Petstore OpenAPI 3 and Swagger 2 specs in test/fixtures/.
License
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.
MCP server for StyleKit styles, tokens, recipes, lint and repair over stdio or HTTP.
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Generate a typed SDK, CLI, and MCP server from any OpenAPI or GraphQL spec, and keep them current.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceConfigurable MCP server that converts any OpenAPI specification into MCP tools over HTTP, with support for dynamic reloading and environment variable expansion for secrets.MIT
- 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
- AlicenseNot gradedqualityCmaintenanceTurns any API with an OpenAPI 3.0/3.1/3.2 spec into callable MCP tools: it generates a tool per supported operation, validates arguments, and forwards authenticated requests, served over stdio or local HTTP or embedded as a library. No hand-written tool per endpoint is required.MIT
- AlicenseNot gradedqualityCmaintenanceConverts OpenAPI 3.x and Swagger specifications into MCP tools. Supports Streamable HTTP, stdio, and legacy SSE, with optional upstream host allowlisting, API-key forwarding, and BI-SNAP request signing.1MIT