openapi-to-mcp

openapi-to-mcp

Converts 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.

Category
Visit Server

README

<div align="center">

πŸ”Œ openapi-to-mcp

Turn any OpenAPI 3.x spec into a live MCP server. Point it at a spec (file or URL) and every endpoint becomes a validated tool your AI agent can call β€” no glue code, no per-API server to write.

CI npm tests node license

Quick start Β· How it maps Β· Config Β· Secure it Β· Limits Β· EspaΓ±ol

</div>

  OpenAPI 3.x spec                         your AI client
 (JSON / YAML, file or URL)               (Claude, Cursor)
          β”‚                                      β”‚
          β–Ό                                      β”‚  MCP / JSON-RPC (stdio)
 [ openapi-to-mcp ]  β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚  GET /pets/{id} β†’ tool "get_pet_by_id"
          β–Ό  HTTP + your auth header
   the underlying REST API

Why

MCP lets an agent call tools, but someone has to write those tools. If the capability you want already exists as a REST API with an OpenAPI spec, writing a bespoke MCP server for it is busywork.

openapi-to-mcp reads the spec and does the mapping for you: each METHOD /path becomes a tool, each parameter and request body becomes a Zod-validated input, and every call is turned into an HTTP request with your auth header attached. The response comes back trimmed for an LLM context window.

Quick start

No install needed β€” run it straight from npm:

npx @karlangas12/openapi-to-mcp --spec https://api.example.com/openapi.json \
  --auth-header "Authorization: Bearer YOUR_TOKEN"

See what tools a spec produces without starting a server:

npx @karlangas12/openapi-to-mcp --spec ./openapi.yaml --list

Claude Desktop β€” claude_desktop_config.json

{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": [
        "-y", "@karlangas12/openapi-to-mcp",
        "--spec", "https://petstore3.swagger.io/api/v3/openapi.json",
        "--auth-header", "Authorization: Bearer YOUR_TOKEN"
      ]
    }
  }
}

Cursor β€” .cursor/mcp.json

{
  "mcpServers": {
    "my-api": {
      "command": "npx",
      "args": [
        "-y", "@karlangas12/openapi-to-mcp",
        "--spec", "./openapi.yaml",
        "--base-url", "https://api.internal.company.com"
      ]
    }
  }
}

That's the whole integration. Restart the client and the API's endpoints show up as tools.

How it maps

OpenAPI Becomes
operationId, or METHOD /path if absent Tool name (get_pets_by_pet_id)
summary / description Tool description
Path, query and header parameters Tool input properties (path params are required)
requestBody (application/json) A body input property
Every input schema A Zod validator + a JSON Schema for tools/list
Local $ref (#/components/...) Resolved inline
enum, minimum/maximum, required, nullable, oneOf/anyOf/allOf Enforced on input

When the agent calls a tool, arguments are validated before any HTTP request goes out. Path params are substituted into the URL, query params are appended, header params and your static --auth-header values are sent, and a JSON body is serialized. A 4xx/5xx response comes back as an error result the model can read and react to β€” not a silent failure.

Configuration

openapi-to-mcp --spec <path|url> [options]

  -s, --spec <path|url>    OpenAPI 3.x spec (JSON or YAML, local or remote)
      --base-url <url>     API base URL (when the spec declares no "servers")
  -H, --auth-header <h>    Header to forward, "Name: value" (repeatable)
      --format <mode>      Response format: markdown (default) or json
  -n, --name <name>        MCP server name
      --list               Print the generated tools and exit
  -h, --help / -v, --version

Multiple headers:

npx @karlangas12/openapi-to-mcp --spec ./api.yaml \
  --auth-header "Authorization: Bearer XYZ" \
  --auth-header "X-Api-Version: 2024-01"

Export a standalone server (codegen)

npx @karlangas12/openapi-to-mcp codegen --spec ./api.yaml -o server.ts

Writes a single self-contained TypeScript file that embeds the spec and boots the server via this package β€” handy for committing a pinned server to a repo.

Pairing with mcp-shield-proxy

openapi-to-mcp talks to a third-party API on your behalf, with your credentials. If you want a policy, credential masking and an audit trail around that, wrap it with mcp-shield-proxy β€” they compose with one extra line:

{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": [
        "-y", "mcp-shield-proxy", "--",          // ← inspect, mask, audit
        "npx", "-y", "@karlangas12/openapi-to-mcp",
        "--spec", "https://api.example.com/openapi.json",
        "--auth-header", "Authorization: Bearer YOUR_TOKEN"
      ]
    }
  }
}

Now every generated tool call is policy-checked, credentials in the traffic are masked, and the whole session lands in a verifiable audit log.

Use as a library

import { loadSpec, buildTools, createMcpServer, startStdioServer } from '@karlangas12/openapi-to-mcp';

const doc = await loadSpec('./openapi.yaml');
const { tools, baseUrl } = buildTools(doc);

const server = createMcpServer({
  tools,
  baseUrl: baseUrl ?? 'https://api.example.com',
  headers: { Authorization: 'Bearer YOUR_TOKEN' },
  fetchFn: (url, init) => fetch(url, init as RequestInit),
});

startStdioServer(server);

The parser, the schema→Zod converter and the tool builder are all exported independently.

Honest limitations

  • stdio transport only. The MCP server speaks stdio, which covers Claude Desktop, Cursor and Claude Code. Native HTTP/SSE serving isn't implemented yet.
  • Local $ref only. References inside the document (#/components/...) are resolved. External refs (other files or URLs) are not β€” they raise a clear error rather than failing quietly.
  • application/json bodies. Request bodies are mapped for JSON content. multipart/form-data and application/x-www-form-urlencoded aren't mapped yet.
  • It's a mapper, not a gateway. It doesn't add retries, caching or rate limiting. Pair it with a proxy if you need those.

Performance

The spec is parsed once at startup; after that, each tool call is a schema validation plus one HTTP request. Parsing and tool generation for a typical spec is sub-millisecond β€” the latency you feel is the underlying API's, not this.

Testing

npm test          # 32 tests
npm run typecheck # strict TypeScript

Coverage includes JSON and YAML parsing, endpoint→tool conversion with Zod schemas, and a full tools/call round trip over JSON-RPC against a mocked HTTP backend (asserting the URL, method, headers and body that reach it).

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured