Skip to main content

swagger-mcp

Your AI assistant knows everything except your internal APIs. swagger-mcp reads any Swagger/OpenAPI spec and bridges it to AI clients as structured tools, no glue code, no manual wiring, no stale context.

The Problem

Your AI assistant can write code, debug logic, and look up documentation, but the moment you ask it about your internal REST API, it hallucinates endpoints and makes up field names. The spec exists; the AI just can't see it.

What It Does

swagger-mcp is an MCP server that reads any Swagger/OpenAPI definition and exposes it to AI clients as structured, queryable tools. Point it at your API spec, connect your AI assistant, and you can explore endpoints, inspect schemas, generate Go scaffolding, or proxy live requests, instantly.

How It Works

swagger-mcp parses your OpenAPI spec and registers a set of MCP tools the AI can call directly:

  • listEndpoints: enumerate all routes with HTTP methods and summaries
  • listEndpointModels: fetch request/response schemas for a specific route
  • generateModelCode: emit a Go struct for any schema model
  • generateEndpointToolCode: scaffold a Go MCP tool handler for an endpoint
  • generateServer: generate a complete, runnable Go MCP server project

In proxy mode (--proxy-mode), every Swagger endpoint is dynamically registered as a callable MCP tool. The server forwards each AI tool invocation as a live HTTP request to your real API, with anti-hallucination guards baked in to prevent the model from fabricating response data.

Features

  • 🔌 Three transport modes: stdio (Cursor, Claude Desktop), sse, and streamable-http
  • 🚦 Endpoint filtering: include/exclude paths and HTTP methods via regex
  • 🔐 Full auth support: API Key, Bearer/JWT, Basic Auth, OAuth2 client credentials
  • 🛠️ CLI inspection: inspect endpoints, inspect endpoint, inspect security, inspect models
  • 🏗️ Go code generation: structs, tool handlers, and complete server scaffolding
  • 📦 Smart spec caching: specs cached locally with ETag/Last-Modified revalidation
  • 🖥️ Built-in web UI: interactive dashboard for manual tool testing
  • 🗂️ Per-project config: .swagger-mcp file sets spec location per directory

Installation

# Build from source
git clone https://github.com/caioreix/swagger-mcp.git
cd swagger-mcp
make build   # → build/swagger-mcp

# Or with Docker
docker build -t swagger-mcp .

Usage

Connect Cursor to any API in 30 seconds:

./build/swagger-mcp --swagger-url="https://petstore.swagger.io/v2/swagger.json"

In Cursor → Settings → Features → MCP → + Add New MCP Server:

FieldValue
Transportstdio
Command/path/to/swagger-mcp --swagger-url=https://your-api/swagger.json

Proxy mode: every endpoint becomes a live tool:

./build/swagger-mcp --proxy-mode \
  --swagger-url="https://your-api/swagger.json" \
  --include-paths="^/v2/.*" \
  --exclude-methods="DELETE"

Authenticate with environment variables:

BEARER_TOKEN=my-jwt ./build/swagger-mcp --proxy-mode \
  --swagger-url="https://your-api/swagger.json"

Configuration

FlagEnv VariableDescription
--swagger-urlSWAGGER_MCP_SWAGGER_URLURL of the Swagger/OpenAPI definition
--transportSWAGGER_MCP_TRANSPORTstdio, sse, or streamable-http
--portSWAGGER_MCP_PORTHTTP port for SSE/StreamableHTTP (default: 8080)
--proxy-modeSWAGGER_MCP_PROXY_MODEDynamic proxy: each endpoint becomes an MCP tool
--base-urlSWAGGER_MCP_BASE_URLOverride the base URL from the spec
--include-pathsSWAGGER_MCP_INCLUDE_PATHSRegex patterns for paths to expose
--exclude-pathsSWAGGER_MCP_EXCLUDE_PATHSRegex patterns for paths to hide
--include-methodsSWAGGER_MCP_INCLUDE_METHODSHTTP methods to expose: GET,POST
--exclude-methodsSWAGGER_MCP_EXCLUDE_METHODSHTTP methods to hide: DELETE,PUT
--uiSWAGGER_MCP_UIEnable the built-in web UI

Give your AI assistant eyes on your API: grab swagger-mcp on GitHub.

Comments

0/280
swagger-mcp