OpenAPI / Swagger → live MCP server

Point openapi-mcp-runtime at any OpenAPI 3.0, 3.1 or Swagger 2.0 document and every API operation becomes a tool your AI agents can call — with auth, caching and typed arguments. No wrapper code, no build step.

npm openapi-mcp-runtime Node ≥ 18.17 License MIT Maintainer japofc
$ npx openapi-mcp-runtime ./petstore.yaml

Features

A runtime, not a code generator. The server proxies the live API, so spec changes take effect on restart.

Zero-config

One command, any spec. Tools are live immediately.

stdio + HTTP + SSE

Claude Desktop / Cursor over stdio, modern clients over Streamable HTTP, older clients over legacy SSE.

Resilient

Exponential-backoff retries and optional hot-reload of the spec file.

Namespaced tools

Serve several APIs side by side with --tool-prefix.

Full security

apiKey, bearer, basic, OAuth2 client credentials.

Typed tools

Arguments derive from the spec's JSON Schemas.

GET caching

Optional TTL cache for idempotent reads.

Any $ref

Internal, external-file and remote refs are dereferenced.

Tiny

2 runtime dependencies, ESM-native TypeScript.

Library + CLI

Use it programmatically or from the terminal.

Quickstart

Serve a spec, then connect any MCP client.

stdio
HTTP
Inspect tools
# Serve over stdio (JSON-RPC on stdin/stdout)
npx openapi-mcp-runtime ./petstore.yaml

# Logs go to stderr, so stdout stays clean JSON-RPC
[openapi-mcp] Loaded OpenAPI 3.0.3 — 3 tool(s) exposed.
[openapi-mcp] Base URL: https://petstore3.swagger.io/api/v3
npx openapi-mcp-runtime ./petstore.yaml --transport http --port 8787
# MCP endpoint:  http://127.0.0.1:8787/mcp
# Health check:  http://127.0.0.1:8787/health
npx openapi-mcp-runtime ./petstore.yaml --print-tools

Example spec: examples/petstore.yaml in the repository.

Integrations

Ready-made configs and framework adapters. All examples live in examples/integrations/.

Claude Desktop
Cursor
Hono
Next.js
// ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": ["-y", "openapi-mcp-runtime", "./examples/petstore.yaml"]
    }
  }
}
// .cursor/mcp.json
{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": ["-y", "openapi-mcp-runtime", "./examples/petstore.yaml"]
    }
  }
}
// examples/integrations/hono.ts — Hono server with an MCP endpoint
import { Hono } from "hono";
import { createHandler, createRuntime, executeTool, loadSpec } from "openapi-mcp-runtime";

const runtime = createRuntime(await loadSpec("./examples/petstore.yaml"));
const handler = createHandler({ tools: runtime.tools, execute });

const app = new Hono();
app.post("/mcp", async (c) => {
  const response = await handler(await c.req.json());
  return response === null ? new Response(null, { status: 202 }) : c.json(response);
});
app.get("/health", (c) => c.json({ ok: true }));
// app/api/mcp/route.ts — Next.js App Router
import { createHandler, createRuntime, executeTool, loadSpec } from "openapi-mcp-runtime";

const runtime = createRuntime(await loadSpec("./examples/petstore.yaml"));
const handler = createHandler({ tools: runtime.tools, execute });

export async function POST(request: Request) {
  const response = await handler(await request.json());
  return response === null ? new Response(null, { status: 202 }) : Response.json(response);
}
export async function GET() {
  return Response.json({ ok: true, tools: runtime.tools.length });
}

CLI reference

All options can be combined. Logs go to stderr; --print-tools writes JSON to stdout.

OptionDescription
--transport <stdio|http|sse>Transport to serve (default stdio); sse is the legacy HTTP+SSE transport.
--port <number>HTTP port (default 8787).
--host <host>HTTP host (default 127.0.0.1; use 0.0.0.0 to expose).
--server <url>Override the server URL from the spec.
--header <NAME=VALUE>Extra header, repeatable. ${ENV_VAR} is expanded.
--bearer <token>Bearer token for http bearer schemes.
--basic <USER:PASS>Basic auth credentials.
--api-key <NAME=VALUE>Value for an apiKey scheme, repeatable.
--oauth2 <SCHEME=ID:SECRET>OAuth2 client credentials, repeatable.
--scope <SCHEME=a,b>OAuth2 scopes, repeatable.
--cache-ttl <seconds>Cache GET responses for N seconds (default 0).
--timeout <ms>Request timeout in milliseconds (default 30000).
--retries <n>Extra attempts for network failures and 5xx responses (default 0).
--watchReload automatically when a local spec file changes.
--tool-prefix <prefix>Prefix every tool name, e.g. petstore_getPets.
--print-toolsPrint generated tools as JSON and exit.
--generate-types <file>Write TypeScript argument types to a file.
--generate-client <file>Write a self-contained TypeScript client.
--verboseLog more detail to stderr.

Authentication

Credentials are matched to the spec's securitySchemes by name. Missing credentials never crash the server — the call proceeds unauthenticated and the API decides.

# apiKey scheme
npx openapi-mcp-runtime ./api.yaml --api-key apiKey=my-secret

# bearer
npx openapi-mcp-runtime ./api.yaml --bearer "$TOKEN"

# basic
npx openapi-mcp-runtime ./api.yaml --basic user:pass

# OAuth2 client credentials (tokenUrl comes from the spec)
npx openapi-mcp-runtime ./api.yaml --oauth2 myOAuth=client-id:client-secret --scope myOAuth=read,write

# static header, env var expanded at startup
npx openapi-mcp-runtime ./api.yaml --header "X-Tenant=$TENANT_ID"

Programmatic API

The same building blocks the CLI uses, available as an ESM/TypeScript library.

import { createHandler, createRuntime, executeTool, loadSpec, startHttpServer } from "openapi-mcp-runtime";

const spec = await loadSpec("./petstore.yaml");   // file or URL, $refs resolved
const runtime = createRuntime(spec, { baseUrl: "https://api.example.com" });

const tool = runtime.tools.find((t) => t.name === "listPets");
const result = await executeTool(tool, { limit: 10 }, {
  baseUrl: runtime.baseUrl,
  auth: { bearer: process.env.TOKEN },
  security: tool.security,
  securitySchemes: runtime.securitySchemes,
  cacheTtl: 60,
});

const handler = createHandler({ tools: runtime.tools, execute });
await startHttpServer(handler, { port: 8787 });

Generate a typed client

npx openapi-mcp-runtime ./api.yaml --generate-client ./api-client.ts
import { callTool } from "./api-client.ts";
const pets = await callTool("listPets", { limit: 10 });

FAQ

Short answers to the questions that come up most.

Which specification versions are supported?

OpenAPI 3.0.x, 3.1.x and Swagger 2.0, in JSON or YAML, from a local file or an http(s):// URL. Internal, external-file and remote $refs are dereferenced.

How do tools get their names?

operationId when present; otherwise a sanitized method_path form. Names are unique, MCP-safe ([a-zA-Z0-9_-], max 64 chars). Use x-mcp-exclude: true on an operation to hide it.

How are request bodies mapped?

An object body schema's properties become top-level tool arguments. Non-object bodies are exposed as a single body argument. Path, query and header parameters are mapped to their own arguments.

Which Node versions work?

Node.js 18.17 and newer (the package uses global fetch and AbortSignal.timeout).

How does the HTTP transport work?

Streamable HTTP: POST /mcp for JSON-RPC requests, GET /mcp for the server event stream, GET /health for liveness. CORS is open so browser-based clients can connect.

Is this affiliated with the OpenAPI or Anthropic projects?

No. Independent, MIT-licensed tooling maintained by japofc.

Can I fork and rebrand it?

The code is MIT, so you may fork, modify and redistribute it as long as the copyright notice and license text stay intact. The name japofc and the project branding are trademarks and are not licensed — see TRADEMARK.md in the repository.