TypeScript · Node 18+ · MIT · on npm

Your API, as tools Claude can call.

api2mcp serves any OpenAPI 3.x or Swagger 2.x spec as a local MCP server over stdio. Every operation becomes a tool. When the model calls one, the request goes to the real API with your auth injected, and the response comes back as the tool result.

Every Petstore endpoint, now a tool

npx @swayam5342/api2mcp --url https://petstore3.swagger.io/api/v3/openapi.json
  1. MCP clientClaude calls findPetsByStatus
  2. api2mcpbuilds the request from the spec, adds your headers
  3. upstreamGET /pet/findByStatus?status=available
  4. back to Claudethe JSON response, as the tool result

No telemetry. No database. No eval. The only network traffic is the upstream calls you configure, plus fetching the spec if you pass a URL.

One operation in, one tool out

Pick a Petstore operation to see the tool api2mcp registers for it. Path, query and header params become top-level fields; a JSON object body is flattened into them. A fixed param disappears from the schema and is injected into the request instead.

In the spec


      
tools/list

      
the upstream request

      

Auth the model never sees

Headers and fixed params are added by api2mcp, not by the model. The key is never in a tool schema, so the model can't leak it or put it somewhere it shouldn't.

Fixed params

Injected into every request, hidden from every schema

If the spec declares a matching parameter, the value goes in that place. Unknown keys go in the query string. Write them as key=value, a=1,b=2 or a JSON object.

Redaction

*** in every log line

Every header and fixed-param value is redacted from logs and error messages, even when the upstream echoes it back in an error body.

Arguments

Keep keys off the command line

Other users can see process arguments with ps. Pass secrets through your MCP client's env field instead.

Add it to your client

Fill in your API and copy the config. The token goes in env, never in args. Restart Claude Desktop and the operations show up as tools named after their operationId.

Flags, variables, a config file

Every setting can come from a flag, an environment variable or a config file in the working directory, in that order of precedence: flags win, then the environment, then the file.

Command-line flags
FlagEnvWhat it does
-u, --urlOPENAPI_URLSpec file path or URL
-b, --base-urlAPI_BASE_URLUpstream base URL; overrides the spec's servers
--headersAPI_HEADERSUpstream headers as a JSON object
-f, --fixed-paramsAPI_FIXED_PARAMSParams injected into every request, hidden from the model
-p, --prefixPrefix for tool names: myapi_listPets
-t, --timeoutAPI_TIMEOUTUpstream timeout in ms (default 30000)
-d, --debugDEBUGVerbose logs to stderr, secrets redacted

api2mcp.json (or api2mcp.config.json, .api2mcp.json)

{
  "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"
}

Or use it as a library

import { createServer, resolveConfig } from "@swayam5342/api2mcp";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const config = await resolveConfig({ url: "./openapi.json" });
const server = await createServer(config);
await server.connect(new StdioServerTransport());

Limits in v1: JSON request bodies only (no multipart or form-urlencoded), cookie params are ignored, and every operation is registered up front, with no on-demand mode for very large specs. For a curated server built from the same idea, see plugit.