Skip to main content
Glama
OpenAPI REST MCP Server

OpenAPI REST MCP Server

by sametbrr

npm version License: MIT

Quick Start • Installation • Usage • Configuration • Troubleshooting • Contributing

OpenAPI REST MCP Server

A Model Context Protocol (MCP) server that lets Claude AI talk to any OpenAPI/Swagger REST API through CRUD operations — works with .NET, Node, Spring, FastAPI and more. Flexible per-environment authentication (including zero-config auto-login), ${ENV_VAR} secret injection, fuzzy endpoint search, and $ref-inlined schema discovery.

🇹🇷 Türkçe için README.tr.md


Quick Start

Claude Desktop — add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{ "mcpServers": { "openapi-rest": { "command": "npx", "args": ["-y", "openapi-rest-mcp", "--config", "/path/to/config.json"] } } }

Claude Code:

npm install openapi-rest-mcp
claude mcp add openapi-rest openapi-rest-mcp -- --config /absolute/path/to/config.json

Then copy and fill in config.json — see Configuration.


Related MCP server: mcp-openapi

Features

All HTTP methods

GET, POST, PUT, DELETE and PATCH against any REST API

Swagger/OpenAPI integration

Reads the spec and inlines $ref schemas

Multiple environments

Named environments (local, development, beta, production, …) with a switchable default

Endpoint discovery

Fuzzy keyword search, tag/method filters and schema retrieval from Swagger

Flexible auth

Per-environment none, bearer, apiKey, basic or login

Zero-config login

Auto-discovers the login endpoint and auto-detects the token in the response

inspect_login tool

Finds the right token path without guessing

Response truncation

maxResponseChars / per-call maxChars protect the context window

${ENV_VAR} substitution

Keeps secrets out of config.json

Configurable config path

--config flag or OPENAPI_MCP_CONFIG environment variable

TLS control and caching

Per-environment TLS verification and Swagger response caching


Requirements

  • Node.js 22 or later (LTS)

  • Any REST API with an OpenAPI/Swagger JSON endpoint (.NET, Node, Spring, FastAPI, …)


Installation

npm install -g openapi-rest-mcp   # global — for Claude Desktop
npm install openapi-rest-mcp      # local  — for Claude Code projects

Check that the binary runs:

npx openapi-rest-mcp --version
npx openapi-rest-mcp --help

Usage

URLs can be absolute (https://host/path) or relative to the environment's baseUrl (e.g. /users). Every tool also accepts environment (override the active one) and maxChars (0 = unlimited). api_* tools also accept includeHeaders.

Tool

Description

api_get

GET request

api_post

POST request (create)

api_put

PUT request (replace)

api_delete

DELETE request

api_patch

PATCH request (partial update)

inspect_login

Probe the login endpoint; return raw response + suggested token paths

swagger_fetch

Fetch & summarize Swagger doc

swagger_list_endpoints

List endpoints (search keyword, tag/method filters, limit)

swagger_get_endpoint

Endpoint detail with $ref inlining

swagger_get_schema

Schema/model definition

config_status

Where config is looked for + whether it loaded

config_init

Write a starter config.json (path, force)

Examples:

api_get("/users", { include: "profile" })
api_post("/users", { name: "John Doe", email: "john@example.com" })
api_put("/users/123", { name: "Jane Doe" })
api_delete("/users/123")
api_patch("/users/123", { email: "new@example.com" })
api_get("/reports/huge", {}, { maxChars: 0 })   // unlimited

inspect_login({ environment: "local" })
swagger_fetch({ environment: "beta" })
swagger_list_endpoints({ search: "order create", limit: 10 })
swagger_list_endpoints({ tag: "User", method: "POST" })
swagger_get_endpoint({ path: "/api/users/{id}", method: "GET" })
swagger_get_schema({ schemaName: "UserDto" })

Configuration

Copy the example and edit it:

cp node_modules/openapi-rest-mcp/config.example.json config.json

Minimal config.json:

{
  "environments": {
    "local": {
      "baseUrl": "https://localhost:7000/api",
      "swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json"
    }
  },
  "activeEnvironment": "local",
  "timeout": 30000,
  "headers": {
    "Content-Type": "application/json",
    "Accept": "application/json"
  }
}

Config file resolution order

  1. --config <path> / -c <path> — CLI flag

  2. OPENAPI_MCP_CONFIG — environment variable (DOTNET_API_CONFIG also accepted)

  3. ./config.json — current working directory

openapi-rest-mcp --config /etc/openapi-mcp/config.json
OPENAPI_MCP_CONFIG=/etc/openapi-mcp/config.json openapi-rest-mcp

First-run setup

No config yet? The server still starts — it won't crash. Configure it with the built-in tools (Claude calls them automatically):

  • config_init — writes a starter config.json at the resolved path (or a custom path).

  • config_status — reports the resolved path, whether it loaded, and the active environment.

After you create/edit config.json it's picked up automatically on the next tool call — no restart needed. Keep secrets out of the file with ${ENV_VAR} placeholders.

Config field reference

Field

Scope

Default

Description

environments

root

—

Map of named environments (required)

activeEnvironment

root

—

Default environment to use (required)

timeout

root

30000

Request timeout in ms

swaggerCacheTtl

root

300

Seconds to cache Swagger docs

maxResponseChars

root

100000

Max chars per tool response (0 = unlimited; override per call with maxChars)

headers

root

JSON defaults

Headers merged into every request

rejectUnauthorized

root / env

true (auto-false for localhost)

TLS verification

maxRedirects

root

0

HTTP redirects to follow (0 = none, avoids leaking auth across hosts)

maxContentLength

root

10485760

Max response/request bytes (DoS guard)

baseUrl

env

—

Base URL for relative paths

swaggerUrl

env

—

Swagger/OpenAPI JSON URL

auth

env

none

Authentication block (see below)

Any string value may contain ${ENV_VAR} placeholders, replaced with the matching environment variable at load time.

Authentication

Auth is configured per environment via an auth object with a type. Omit the auth block entirely if your API is public.

bearer — static bearer token:

"auth": { "type": "bearer", "token": "${API_TOKEN}" }

apiKey — API key in a header or query:

"auth": { "type": "apiKey", "in": "header", "headerName": "X-Api-Key", "value": "${API_KEY}" }

basic — HTTP basic auth:

"auth": { "type": "basic", "username": "${API_USER}", "password": "${API_PASS}" }

login — POST credentials, then reuse the returned token (cached and refreshed automatically).

loginUrl, tokenPath and the expiry fields are all optional — when omitted, the server auto-discovers the login endpoint from the Swagger spec and auto-detects the token in the response.

Zero-config (auto):

"auth": {
  "type": "login",
  "credentials": { "email": "${API_USER}", "password": "${API_PASS}" }
}

Explicit (manual):

"auth": {
  "type": "login",
  "loginUrl": "https://api.example.com/api/auth/login",
  "credentials": { "email": "${API_USER}", "password": "${API_PASS}" },
  "tokenPath": "data.accessToken",
  "expiresInPath": "data.expiresIn",
  "headerName": "Authorization",
  "headerPrefix": "Bearer "
}

Note: if auto-detection picks the wrong token, run the inspect_login tool — it posts your credentials and returns the raw response plus suggested tokenPath values.

login field

Required

Description

credentials

recommended

Body posted to the login endpoint

loginUrl

optional

Login endpoint; auto-discovered from Swagger if omitted

tokenPath

optional

Dot-path to the token; auto-detected if omitted

expiresIn / expiresInPath

optional

Token lifetime (seconds / response path); auto-detected if omitted

headerName / headerPrefix

optional

Defaults to Authorization / Bearer

method / headers

optional

Login request method (default POST) and extra headers

Heads up: when migrating from 1.x, note that the old flat auth: { email, password } is no longer supported. Move those values into an auth object — most APIs map to type: "login" or type: "basic".

Multiple environments

Define as many environments as you need and switch via activeEnvironment (or pass environment to any tool).

{
  "environments": {
    "local":       { "baseUrl": "https://localhost:7000/api", "swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json" },
    "development": { "baseUrl": "https://dev-api.example.com/api", "swaggerUrl": "https://dev-api.example.com/swagger/v1/swagger.json" },
    "beta":        { "baseUrl": "https://beta-api.example.com/api", "swaggerUrl": "https://beta-api.example.com/swagger/v1/swagger.json" },
    "production":  {
      "baseUrl": "https://api.example.com/api",
      "swaggerUrl": "https://api.example.com/swagger/v1/swagger.json",
      "rejectUnauthorized": true,
      "auth": { "type": "bearer", "token": "${PROD_API_TOKEN}" }
    }
  },
  "activeEnvironment": "local"
}

Troubleshooting

No config found — run the config_init tool, then fill in config.json.

Relative URL requires a baseUrl — add baseUrl to the environment.

Failed to fetch Swagger — check that swaggerUrl is reachable from the machine running the server.

Login ... failed — check loginUrl, credentials and tokenPath; run inspect_login to see the raw response.

TLS / certificate errors — set rejectUnauthorized: false for that environment.


Security

The server holds API credentials and forwards them on the model's behalf:

  • Host allowlist: auth tokens are attached only when the target host matches the environment's baseUrl/swaggerUrl/loginUrl. Calls to unrelated absolute URLs are sent without credentials.

  • No redirects by default (maxRedirects: 0) so auth can't be carried to another host; set maxRedirects in config to opt in.

  • inspect_login masks token/password values in its output; config_init only writes inside the project/config directory; response headers are omitted unless you pass includeHeaders: true.

  • Keep secrets in ${ENV_VAR} placeholders, not literals; config.json is git-ignored.


Development

git clone https://github.com/sametbrr/openapi-rest-mcp.git
cd openapi-rest-mcp
npm install
npm start          # run the server
npm run dev        # auto-reload
npm test           # mock-API smoke test

Publishing

Pushing a vX.Y.Z git tag triggers the GitHub Actions workflow that publishes to npm and creates a GitHub Release. The tag must match the version in package.json. Publishing uses npm trusted publishing (OIDC) from the protected npm environment, so no npm token is stored, and every release carries a provenance statement.

git tag v2.1.0
git push origin v2.1.0


Contributing


License

MIT — see LICENSE.


Report Bug · Request Feature

Available Tools

12 tools
api_deleteC

DELETE request to an API endpoint

Inputs: url (required), data, params, headers, +3 more.

api_getC

GET request to an API endpoint

Inputs: url (required), params, headers, maxChars, +2 more.

api_patchB

PATCH request to an API endpoint

Inputs: url (required), data (required), params, headers, +3 more.

api_postC

POST request to an API endpoint

Inputs: url (required), data (required), params, headers, +3 more.

api_putC

PUT request to an API endpoint

Inputs: url (required), data (required), params, headers, +3 more.

config_initA

Write a starter config.json (from config.example.json) so the user can fill it in. Writes to the resolved config path by default; will not overwrite unless force is true.

Inputs: path, force, maxChars.

config_statusA

Report where the config is looked for, whether it was found/loaded, the active environment, and the available environments. Use this to diagnose setup issues.

Inputs: maxChars.

inspect_loginA

POST credentials to the login endpoint and return the raw response plus suggested token paths. Use this to discover the right auth.tokenPath (and verify auto-discovered loginUrl) without committing config.

Inputs: loginUrl, maxChars, credentials, environment.

swagger_fetchC

Fetch and summarize Swagger/OpenAPI documentation for an environment

Inputs: maxChars, environment.

swagger_get_endpointC

Get detailed information about a specific endpoint from Swagger

Inputs: path (required), method (required), maxChars, environment, +1 more.

swagger_get_schemaC

Get a schema/model definition from Swagger documentation

Inputs: schemaName (required), maxChars, environment, resolveRefs.

swagger_list_endpointsB

List API endpoints from Swagger. Optionally fuzzy-search by keyword and/or filter by tag and method.

Inputs: tag, limit, method, search, +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 12 tools

    Disambiguation4/5

    The api_* tools are cleanly separated by HTTP verb, and config_status/config_init and inspect_login have clear unique roles. The only soft overlap is between swagger_fetch (whole-spec summary) and swagger_list_endpoints (filtered endpoint listing), plus inspect_login vs api_post, but descriptions make the intended use cases distinguishable.

    Naming Consistency4/5

    All names use snake_case with a domain prefix (api_, swagger_, config_) plus a verb, which is predictable and readable. The mix of prefixes is natural for this surface, though inspect_login breaks the prefix pattern and api_get-style verb-last ordering differs from swagger_list_endpoints verb-first ordering.

    Tool Count5/5

    Twelve tools is well within the sweet spot for an OpenAPI/REST client. Each tool maps to a distinct capability (five HTTP methods, four swagger-inspection helpers, config diagnostics, login probing) with no filler.

    Completeness4/5

    CRUD coverage via HTTP verbs is complete, and swagger fetching/listing/detail/schema plus config init/status cover discovery and setup. Minor gaps remain: no HEAD/OPTIONS support, and no way to update or reset config or manage multiple environments beyond what config_init/status imply.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Enables interaction with any REST API through token or login authentication, with automatic Swagger/OpenAPI documentation integration for endpoint discovery and comprehensive HTTP request support.
      7
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to discover, search, and call any REST API described by an OpenAPI or Swagger document. Supports multiple API endpoints with authentication and parameter handling.
      14 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables Claude to discover and call any REST API from an OpenAPI/Swagger spec or Postman collection at runtime, with authentication, workflows, and prebuilt registry support.
      MIT