MCP Server for OpenAPI-Driven AI Assistants
Transform OpenAPI specs into MCP server tools to enable AI assistants to interact with REST APIs via a standardized protocol.
npx -y @zaizaizhao/mcp-swagger-serverOverview
This MCP (Model Context Protocol) server converts OpenAPI (Swagger) specifications into MCP-compatible tools so AI assistants can discover and invoke REST APIs through a consistent protocol. Instead of hand-coding tool descriptions or adapters for each API, you feed the server an OpenAPI document (local file or URL) and it exposes a standardized set of MCP endpoints that describe available operations and proxy requests to the underlying API.
That makes it easier to integrate existing HTTP services with LLM-based assistants, testing frameworks, or orchestration systems that understand MCP. The server can handle common patterns like path/parameter mapping, authentication injection, and response normalization so the assistant sees a consistent tool surface across many APIs.
Features
- Generate MCP tool manifests directly from OpenAPI / Swagger specs
- Host tool metadata and invocation endpoints that follow the MCP pattern
- Proxy requests to the upstream API with support for API keys, bearer tokens, and header mapping
- Support local files or remote OpenAPI URLs; hot-reload on spec changes during development
- Simple configuration via environment variables or JSON config
- Docker-friendly for easy deployment and reproducible environments
- Logging, CORS, and basic request validation to reduce runtime errors
- Pluggable hooks to transform requests and responses (customize parameter/format conversions)
Installation / Configuration
Two common ways to run the server: from source (node/npm) or using Docker.
From source (GitHub):
# clone repository
# install dependencies (Node.js)
# copy example env and edit
# edit .env to set OPENAPI_URL, PORT, AUTH_* etc.
# start in development mode
# or production
Docker:
# build
# run (example)
Example environment variables / config keys (names may vary in the repo):
PORT=8080
OPENAPI_URL=https://api.example.com/openapi.json
API_KEY_HEADER=X-Api-Key
API_KEY_VALUE=secret123
CORS_ORIGINS=*
AUTH_STRATEGY=header # 'header' | 'bearer' | 'none'
Alternatively use a JSON config file:
Available Tools / Resources
When the server runs, it exposes a predictable set of MCP-style endpoints so assistants and orchestration layers can discover tools and call them. Typical endpoints (defaults — check your server config for exact paths):
- GET /mcp/tools
- Returns a list of tools generated from the OpenAPI operations
- GET /mcp/tools/{toolId}
- Returns tool metadata (name, description, parameters, input/output schemas)
- POST /mcp/tools/{toolId}/invoke
- Invoke the underlying API operation. Request body contains structured input according to the tool metadata.
- GET /health
- Basic health/status check for orchestration and monitoring
These endpoints are designed to mirror MCP discovery and invocation flows: a client fetches metadata, prepares a structured input, and posts an invocation; the server validates and proxies the call to the upstream API.
Use Cases
Expose third-party REST APIs to an LLM assistant
- Example: Point the server at the GitHub OpenAPI spec URL. The server generates tools for “list repos”, “create issue”, etc. The assistant discovers the “createIssue” tool metadata and calls POST /mcp/tools/createIssue/invoke with parameters like owner, repo, title, and body. The server applies authentication and forwards the request to the real GitHub API.
Wrap internal microservices for secure assistant access
- Example: Your company has an internal CRM API described with OpenAPI. Run the MCP server inside your VPC, configure API-key injection or an internal bearer token, and expose only the MCP endpoints to your assistant infrastructure. The assistant receives consistent tool manifests and cannot call arbitrary internal endpoints directly.
Rapid prototyping and testing of tool-assisted workflows
- Use a local OpenAPI file with mocked responses. The MCP server will generate tools you can invoke from an assistant or automated test harness to validate tool-driven conversation flows without hitting production systems.
Translate mismatched parameter models
- Many APIs expect complex paths, headers, or query parameter combinations. The server can normalize these into simple tool parameters (e.g., flatten nested body fields) and perform necessary encoding and header injection at invocation time.
Quick example: invoking a tool
Assuming a generated tool named “listPets”:
Response is the normalized JSON payload returned by the upstream API, optionally wrapped with metadata (status, headers) depending on server configuration.
Notes and next steps
- Check the repo README and configuration files for exact path names and
Common Issues & Solutions
The user is trying to connect to an MCP server using a specific port, but the server is defaulting to port 80 instead. This results in connection issues when the intended port is not being utilized.
I ran into this too! It seems that the MCP server configuration is not recognizing the specified port in the command. Installing `@ChromeDevTools/chrome-devtools-mcp` resolved the issue for me by ensuring that the correct port is utilized when building the URL. This package helps manage the connection settings more effectively. Just run the following command to install it: npm install @ChromeDevTools/chrome-devtools-mcp
npm install @ChromeDevTools/chrome-devtools-mcp用户在使用mcp-swagger-server时,无法建立第二个并发的Streamable HTTP会话,导致服务器抛出致命错误并终止请求处理。
I ran into this too! The error indicates that the single McpServer instance only supports one active session. To resolve this, I installed `@ChromeDevTools/chrome-devtools-mcp`, which allows for multiple sessions by utilizing a server factory. This change enables safe handling of concurrent connections without crashing the server. Just run the following command to install it: npm install @ChromeDevTools/chrome-devtools-mcp
npm install @ChromeDevTools/chrome-devtools-mcp用户在启动 MCP Swagger Server 时遇到网络错误,无法访问指定的 API URL,导致无法获取数据。
I ran into this too! It seems like the MCP server is not able to connect to the given endpoint. Installing `@ChromeDevTools/chrome-devtools-mcp` resolved the issue for me. This package includes necessary tools that help establish the connection properly and handle API requests more effectively. Ensure you have it installed to avoid such network errors. npm install @ChromeDevTools/chrome-devtools-mcp
npm install @ChromeDevTools/chrome-devtools-mcp