Skip to main content
Glama
avidianity

mcp-openapi

by avidianity

@avidian/mcp-openapi

MCP server for OpenAPI/Swagger. It lets an AI agent discover, inspect, and call any REST API described by an OpenAPI or Swagger document, while keeping the agent's context footprint small.

Instead of registering one MCP tool per API operation (which pushes every operation's schema into the agent's context up front), this server exposes a small, fixed set of generic meta-tools. The agent loads one or more specs at runtime, searches and inspects their operations on demand, and executes them - all through the same six tools, no matter how large or how many specs are loaded.

Installation

npm (requires Node.js >= 20)

npm install -g @avidian/mcp-openapi

Compiled binary (no runtime needed)

Download from GitHub Releases.

Related MCP server: Swagger/Postman MCP Server

How it works

The server holds an in-memory registry of loaded specs. Each loaded spec is a single OpenAPI/Swagger document (2.0, 3.0, or 3.1) together with its parsed operations, and is identified by a spec id - a lowercase ULID the server generates automatically. The agent discovers spec ids by listing what is loaded, then passes an id to the other tools. Nothing is persisted: a restart starts fresh and re-runs any startup preloads.

Meta-tools

The server registers exactly these six tools, and never one tool per operation:

Tool

What it does

load_spec

Load a spec from a URL, a local file path, or inline JSON/YAML content. Returns a generated spec id and a compact summary.

list_specs

List every loaded spec with its id and summary.

unload_spec

Remove a loaded spec, freeing its operations and cached search index.

search_operations

Search (or, with no query, browse) a spec's operations. Returns compact one-liners; use describe_operation for full detail.

describe_operation

Return one operation's parameters and request-body schema in full, plus a summarized view of its responses.

execute_operation

Perform the real HTTP request for one operation, with arguments grouped by location (path, query, headers, body).

Operations are referenced by their method and path (for example get and /pets/{petId}), exactly as search_operations reports them.

Usage

The server can start empty and let the agent load everything at runtime, or preload one or more specs at startup.

# Start empty; the agent calls load_spec at runtime.
mcp-openapi

# Preload a single spec (the common case).
mcp-openapi https://petstore3.swagger.io/api/v3/openapi.json
mcp-openapi ./openapi.yaml --base-url https://api.internal.example.com --timeout 10000

# Preload several specs, each with its own settings, from a config file.
mcp-openapi --config ./specs.json

CLI shape:

mcp-openapi [<source>] [--base-url <url>] [--credential <name>] [--timeout <ms>] [--config <path>]

The single positional <source> may also come from OPENAPI_URL, which is convenient for MCP client configs.

Config file

A JSON config file preloads any number of specs, each with an optional per-spec base URL and credential reference:

{
  "specs": [
    { "source": "https://api.example.com/openapi.json", "credential": "example" },
    { "source": "./internal.yaml", "base_url": "https://api.internal.example.com" }
  ],
  "max_specs": 20,
  "request_timeout_ms": 30000,
  "max_response_bytes": 100000
}

Unknown keys are rejected so typos surface. A preload that fails to load is logged to stderr and skipped; the server still starts, and the agent can load specs at runtime.

MCP client configuration

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

Configuration

Variable

Description

OPENAPI_CONFIG

Path to a JSON config file listing specs to preload

OPENAPI_URL

Single spec source (URL, local path, or inline content) to preload, if not passed as the CLI argument

OPENAPI_BASE_URL

Base URL override for the OPENAPI_URL / positional spec

OPENAPI_CREDENTIAL

Credential reference name for the OPENAPI_URL / positional spec

OPENAPI_REQUEST_TIMEOUT_MS

Per-request timeout in milliseconds (default 30000)

OPENAPI_MAX_RESPONSE_BYTES

Cap on response bytes read from an upstream API (default 100000)

OPENAPI_MAX_SPECS

Maximum number of specs that may be loaded at once (default 20)

Precedence for these knobs is: environment variable > config file > default. The request timeout additionally accepts the --timeout CLI flag, which wins over the environment variable; the response cap and max-specs knobs have no CLI flag.

Authentication

Credentials are always provisioned by the operator in the environment and resolved server-side; a secret value never passes through the agent.

The recommended approach is credential references. The operator provisions a secret under a reference name, and the agent (or config file) passes only that name to load_spec:

Scheme type

Environment variables (for reference name <REF>)

HTTP bearer

OPENAPI_CRED_<REF>_TOKEN (or bare OPENAPI_CRED_<REF>)

HTTP basic

OPENAPI_CRED_<REF>_USERNAME and OPENAPI_CRED_<REF>_PASSWORD

apiKey (header, query, cookie)

OPENAPI_CRED_<REF>

For example, provisioning OPENAPI_CRED_GITHUB_TOKEN and loading with credential: "github" applies that token to the spec's security scheme(s). A reference is applied only to the schemes named in the document's security requirement, so one secret is not sprayed across unrelated schemes. (When the document declares no top-level security, the reference is applied to every scheme it defines.)

When no credential is given, the server falls back to matching each of the document's security schemes by name (converted to SCREAMING_SNAKE_CASE):

Scheme type

Environment variables (for scheme <SCHEME>)

HTTP bearer

OPENAPI_AUTH_<SCHEME>_TOKEN (or bare OPENAPI_AUTH_<SCHEME>)

HTTP basic

OPENAPI_AUTH_<SCHEME>_USERNAME and OPENAPI_AUTH_<SCHEME>_PASSWORD

apiKey (header, query, cookie)

OPENAPI_AUTH_<SCHEME>

Schemes with no matching environment variable are skipped silently; unsupported types (OAuth2, OpenID Connect) are skipped with a warning. Neither case fails startup.

Security note

load_spec fetches whatever URL or reads whatever local file the agent asks it to, and execute_operation calls the base URL declared by (or overridden for) a loaded spec, attaching the operator-provisioned credentials. This is intrinsic to the tool's purpose, but it means a spec pointing at an internal or metadata endpoint would be fetched and called from wherever the server runs. Run the server in an environment where that request surface is acceptable, and only provision credentials for APIs you intend the agent to call.

Development

# Install dependencies
bun install

# Run in dev mode
bun run dev [<source>]

# Type check
bun run typecheck

# Lint
bun run lint

# Format
bun run format

# Test
bun run test

# Everything the CI gate runs
bun run check

# Build for npm
bun run build

# Compile native binary
bun run compile

ajv is listed as a direct devDependency even though nothing in src/ imports it. It's a workaround: @apidevtools/swagger-parser depends on ajv-draft-04, which only declares ajv as a peer dependency, and Bun's bundler fails to statically resolve that peer dependency when producing standalone binaries (bun run compile) unless ajv is also resolvable as a direct dependency somewhere in the root of the tree. Not needed for bun run build (the npm-published bundle), which keeps @apidevtools/swagger-parser external and lets Node resolve it normally at install time.

License

MIT

A
license - permissive license
-
quality - not tested
A
maintenance

Maintenance

Maintainers
Response time
1wRelease cycle
4Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    -
    quality
    -
    maintenance
    Enables AI agents to dynamically discover and interact with APIs through Swagger/OpenAPI specifications and Postman collections using a strategic four-tool approach. It streamlines API integration by providing universal tools for endpoint discovery, detailed request information, and authenticated execution.
    1
  • A
    license
    A
    quality
    D
    maintenance
    Exposes Swagger/OpenAPI API documentation to AI models, enabling exploration, search, and interaction with endpoints, schemas, and execution of API calls.
    14
    5
    2
    MIT

View all related MCP servers

Related MCP Connectors

  • Stripe-native marketplace where AI agents discover and pay per call for API services.

  • SaaS intelligence for AI agents. 5 unified tools cover 1,000+ services with 91-96% token savings.

  • Gateway between LLM agents and world data through eight tools and a bundled endpoint catalog.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/avidianity/mcp-openapi'

If you have feedback or need assistance with the MCP directory API, please join our Discord server