trackmcp
Back to directory
Docat0209

mcp-openapi

View on GitHub

Turn any OpenAPI/Swagger spec into MCP tools. Zero config, zero code.

3 stars TypeScriptOthers Updated May 13, 2026
aiapi-toolsclaudellmmcpmcp-servermodel-context-protocolopenapiswaggertypescript

Documentation

mcp-openapi

> Turn any OpenAPI/Swagger spec into MCP tools — so Claude and other AI assistants can call your REST APIs.

npm version
License: MIT
npm downloads

Point `mcp-openapi` at any OpenAPI 3.x or Swagger 2.0 spec URL and it generates Model Context Protocol (MCP) tools automatically. No code generation, no config files, no boilerplate. Your AI assistant gets callable tools for every API endpoint in seconds.


Quick Start

1. Run it (no install required):

bash
npx mcp-openapi --spec https://petstore3.swagger.io/api/v3/openapi.json

2. Add it to Claude Desktop (`claude_desktop_config.json`):

json
{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": [
        "mcp-openapi",
        "--spec", "https://petstore3.swagger.io/api/v3/openapi.json"
      ]
    }
  }
}

3. Ask Claude to use it:

> "List all available pets in the store"

Claude sees MCP tools like `find_pets_by_status`, `get_pet_by_id`, `add_pet` and calls them directly.


Why mcp-openapi?

Most MCP-to-API bridges require you to write tool definitions by hand or generate code from a spec. `mcp-openapi` skips all of that.

Featuremcp-openapiHand-written MCP serversGeneric HTTP tools
Zero config setupYesNoPartial
OpenAPI 3.x + Swagger 2.0YesN/AN/A
Flat parameter schemas (LLM-optimized)YesManualNo
Smart tool naming from operationIdYesManualNo
Auth (API key, Bearer, OAuth2)Built-inDIYDIY
Retry with exponential backoffBuilt-inDIYDIY
Response truncation for LLM contextBuilt-inDIYNo

Flat parameter schemas are the key differentiator. Instead of passing nested JSON objects (which LLMs frequently get wrong), `mcp-openapi` flattens path, query, header, and body parameters into a single flat object. This dramatically improves tool-calling accuracy.


How It Works

code
OpenAPI/Swagger Spec          mcp-openapi               AI Assistant
     (URL or file)                                      (Claude, etc.)
          |                         |                         |
          |   1. Parse & validate   |                         |
          |------------------------>|                         |
          |                         |                         |
          |   2. Generate MCP tools |                         |
          |   (one per endpoint)    |                         |
          |------------------------>|                         |
          |                         |                         |
          |                         |   3. Register tools     |
          |                         |   via stdio transport   |
          |                         |------------------------>|
          |                         |                         |
          |                         |   4. AI calls a tool    |
          |                         ||------------------------>|

Each API endpoint becomes one MCP tool:

  • Tool name is derived from `operationId` (converted to `snake_case`) or from `method + path`
  • Parameters are flattened into a single input schema (path, query, header, and body params merged)
  • Responses are truncated to ~50KB to stay within LLM context limits
  • Errors (429, 5xx) trigger automatic retries with exponential backoff (up to 3 retries)

Claude Desktop Integration

Add any API to Claude Desktop by editing your config file:

Location:

  • macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
  • Windows: `%APPDATA%\Claude\claude_desktop_config.json`

Public API (no auth)

json
{
  "mcpServers": {
    "petstore": {
      "command": "npx",
      "args": [
        "mcp-openapi",
        "--spec", "https://petstore3.swagger.io/api/v3/openapi.json"
      ]
    }
  }
}

API with Bearer Token

json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": [
        "mcp-openapi",
        "--spec", "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json",
        "--auth-type", "bearer",
        "--auth-token", "$GITHUB_TOKEN",
        "--prefix", "github",
        "--include", "listReposForAuthenticatedUser,getRepo,listIssues,createIssue"
      ],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    }
  }
}

API with API Key

json
{
  "mcpServers": {
    "weather": {
      "command": "npx",
      "args": [
        "mcp-openapi",
        "--spec", "https://api.weather.example.com/openapi.json",
        "--auth-type", "api-key",
        "--auth-name", "X-API-Key",
        "--auth-value", "$WEATHER_API_KEY",
        "--auth-in", "header"
      ],
      "env": {
        "WEATHER_API_KEY": "your_key_here"
      }
    }
  }
}

CLI Reference

bash
npx mcp-openapi --spec  [options]

General Options

OptionShortDefaultDescription
`--spec ``-s`*required*OpenAPI spec URL or local file path
`--config ``-c`JSON config file path
`--base-url `from specOverride the API base URL
`--prefix `Prefix for all tool names (e.g. `github` -> `github_list_repos`)
`--include `allComma-separated operationIds to include
`--exclude `noneComma-separated operationIds to exclude
`--timeout ``30000`HTTP request timeout in milliseconds
`--max-retries ``3`Max retries on 429/5xx responses
`--header ``-H`Custom header (repeatable)
`--transport ``stdio`Transport type: `stdio` or `sse`
`--port ``3000`Port for SSE transport
`--help``-h`Show help
`--version``-v`Show version
`--license-key `Pro license key (or `$MCP_OPENAPI_LICENSE_KEY` env)
`--server ``0`Select API server by index, partial URL, or exact URL
`--no-doc-warnings`Suppress doc quality warnings on startup
`--dynamic-discovery`auto (100+)Enable dynamic tool discovery for large APIs

Auth Options

Bearer token:

OptionDescription
`--auth-type bearer`Use Bearer token authentication
`--auth-token `The token value (supports `$ENV_VAR` syntax)

API key:

OptionDescription
`--auth-type api-key`Use API key authentication
`--auth-name `Header or query parameter name
`--auth-value `The API key value (supports `$ENV_VAR` syntax)
`--auth-in `Where to send the key (default: `header`)

OAuth2 client credentials:

OptionDescription
`--auth-type oauth2`Use OAuth2 client credentials flow
`--auth-client-id `OAuth2 client ID
`--auth-client-secret `OAuth2 client secret
`--auth-token-url `Token endpoint URL
`--auth-scopes `Comma-separated scopes

CLI Examples

bash
# Basic usage with a remote spec
npx mcp-openapi --spec https://petstore3.swagger.io/api/v3/openapi.json

# Local YAML spec with Bearer auth
npx mcp-openapi --spec ./api.yaml --auth-type bearer --auth-token '$API_KEY'

# Filter to specific endpoints with a prefix
npx mcp-openapi --spec ./api.json --prefix myapi --include 'listUsers,getUser'

# Override base URL (useful for local dev)
npx mcp-openapi --spec https://api.example.com/openapi.json --base-url http://localhost:3000

# Add custom headers
npx mcp-openapi --spec ./api.json -H 'X-Custom: value' -H 'X-Another: value2'

# Use a JSON config file
npx mcp-openapi --config ./mcp-config.json

# Select staging server
npx mcp-openapi --spec ./api.json --server staging

# Large API with dynamic discovery
npx mcp-openapi --spec https://api.stripe.com/openapi.json --dynamic-discovery

Config File Format

Instead of CLI flags, you can use a JSON config file:

json
{
  "spec": "https://api.example.com/openapi.json",
  "prefix": "myapi",
  "include": ["listUsers", "getUser", "createUser"],
  "auth": {
    "type": "bearer",
    "token": "$API_TOKEN"
  },
  "timeout": 15000,
  "maxRetries": 2,
  "headers": {
    "X-Custom-Header": "value"
  }
}

CLI arguments take precedence over config file values.


Supported Specs

FormatVersionsFile types
OpenAPI3.0.x, 3.1.x`.json`, `.yaml`, `.yml`
Swagger2.0`.json`, `.yaml`, `.yml`

Specs can be loaded from:

  • Remote URLs (`https://...`)
  • Local file paths (`./api.yaml`, `/absolute/path/spec.json`)

v0.3.0 Features

Doc Quality Warnings

On startup, `mcp-openapi` checks each tool's documentation quality. If endpoints have sparse descriptions (under 50 characters), you'll see a warning:

code
[mcp-openapi] WARN: Doc quality: 11 of 47 tools have sparse documentation ( Interested in Pro? Star the repo and [open an issue](https://github.com/Docat0209/mcp-openapi/issues) to get early access.

---

## Programmatic Usage

You can also use `mcp-openapi` as a library in your own MCP server:

import { createServer } from 'mcp-openapi';

const { server, tools, spec } = await createServer({

spec: 'https://petstore3.swagger.io/api/v3/openapi.json',

prefix: 'petstore',

auth: {

type: 'bearer',

token: process.env.API_TOKEN,

},

});

console.log(`Loaded ${tools.length} tools from ${spec.info.title}`);

code
---

## Requirements

- Node.js 18 or later
- An OpenAPI 3.x or Swagger 2.0 spec (URL or local file)

---

## Contributing

Contributions are welcome. Here is how to get started:

git clone https://github.com/Docat0209/mcp-openapi.git

cd mcp-openapi

pnpm install

pnpm test

pnpm build

code
Before submitting a PR:
1. Add tests for new features
2. Run `pnpm lint` and fix any issues
3. Follow [Conventional Commits](https://www.conventionalcommits.org/) for commit messages

---

## Related

- [graphql-to-mcp](https://www.npmjs.com/package/graphql-to-mcp) — Same zero-config approach for GraphQL APIs

## License

MIT

---

## Keywords

mcp, model-context-protocol, openapi, swagger, claude, ai, llm, api, tools, rest-api, ai-tools, mcp-server

Frequently asked questions

What is mcp-openapi?

mcp-openapi is Turn any OpenAPI/Swagger spec into MCP tools. Zero config, zero code.

How do I install mcp-openapi?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is mcp-openapi open source?

Yes — it is hosted on GitHub at https://github.com/Docat0209/mcp-openapi and has 3 stars.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP