Swagger MCP is an MCP server that connects to Swagger/OpenAPI specifications to help AI assistants discover, explore, and interact with REST APIs.
Core Capabilities:
Fetch and cache Swagger specifications from URLs (supports JSON and YAML formats)
List API endpoints with HTTP methods and descriptions from the documentation
Inspect endpoint details including parameters, request/response schemas, and descriptions
Execute API requests to any endpoint with support for all HTTP methods, query parameters, request bodies, and custom headers
Validate API responses against Swagger schemas to ensure data integrity and correctness
List and retrieve models defined in the Swagger specification
Generate TypeScript code for MCP tool definitions and models with full schema information and AI-specific instructions
Access guided prompts to assist AI through common workflows like adding new endpoints
Configure via CLI arguments or tool parameters with priority handling for Swagger sources
Integrate with Cursor and other MCP-compatible applications
Use Cases: Dynamically explore unfamiliar APIs, test endpoints with proper validation, verify responses match specifications, build API integrations, and automate testing workflows.
Uses environment configuration for server settings including port, environment type, and logging levels.
Allows connection to any Swagger-defined API, providing tools to download specifications, list endpoints and models, generate TypeScript code for models, and create MCP tool definitions based on API endpoints.
Generates TypeScript code for models and MCP tool definitions from Swagger specifications to build type-safe API integrations.
Supports parsing and handling YAML Swagger definition files to extract API information and generate compatible code.
Swagger MCP
An MCP server that connects to a Swagger specification and helps an AI to build all the required models to generate a MCP server for that service.
Features
Downloads a Swagger specification and stores it locally for faster reference.
Returns a list of all the endpoints and their HTTP Methods and descriptions
Returns a list of all the models
Returns a model
Returns service to connect to the end point
Returns MCP function definitions
Generates complete MCP tool definitions with full schema information
Includes AI-specific instructions in tool descriptions
Related MCP server: swagger-mcp
Prerequisites
Node.js (v14 or higher)
npm or yarn
Installation
Clone the repository:
Install dependencies:
Create a
.envfile based on the.env.examplefile:
Update the
.envfile.
Configuration
Edit the .env file to configure the application:
PORT: The port on which the server will run (default: 3000)NODE_ENV: The environment (development, production, test)LOG_LEVEL: Logging level (info, error, debug)
Usage
Building the application
Build the application:
This will compile the TypeScript code ready to be used as an MCP Server
Running as an MCP Server
To run as an MCP server for integration with Cursor and other applications:
You can also provide a Swagger URL via CLI argument:
Or using the alternative format:
Note: The CLI --swagger-url argument takes priority over the swaggerFilePath parameter in tool calls. If both are provided, the CLI argument will be used.
Using the MCP Inspector
To run the MCP inspector for debugging:
Adding to Cursor
To add this MCP server to Cursor:
Open Cursor Settings > Features > MCP
Click "+ Add New MCP Server"
Enter a name for the server (e.g., "Swagger MCP")
Select "stdio" as the transport type
Enter the command to run the server:
Basic:
node path/to/swagger-mcp/build/index.jsWith Swagger URL:
node path/to/swagger-mcp/build/index.js --swagger-url="https://your-api-url/swagger.json"
Click "Add"
The Swagger MCP tools will now be available to the Cursor Agent in Composer.
Tip: If you provide the --swagger-url CLI argument when configuring the server, you won't need to provide swaggerFilePath in tool calls, making the tools easier to use.
Available Swagger MCP Tools
The following tools are available through the MCP server:
getSwaggerDefinition: Downloads a Swagger definition from a URLlistEndpoints: Lists all endpoints from the Swagger definition (optionalswaggerFilePath)listEndpointModels: Lists all models used by a specific endpoint (optionalswaggerFilePath)generateModelCode: Generates TypeScript code for a model (optionalswaggerFilePath)generateEndpointToolCode: Generates TypeScript code for an MCP tool definition (optionalswaggerFilePath)
Swagger Definition Priority: The tools determine which Swagger definition to use based on this priority:
CLI
--swagger-urlargument (if provided when starting the server)swaggerFilePathparameter (if provided in the tool call)Error if neither is available
If you start the server with --swagger-url, you can omit the swaggerFilePath parameter in tool calls for convenience.
Available Swagger MCP Prompts
The server also provides MCP prompts that guide AI assistants through common workflows:
add-endpoint: A step-by-step guide for adding a new endpoint using the Swagger MCP tools
To use a prompt, clients can make a prompts/get request with the prompt name and optional arguments:
The prompt will return a series of messages that guide the AI assistant through the exact process required to add a new endpoint.
Setting Up Your New Project
There are two ways to set up the Swagger definition for your project:
Method 1: Using CLI Argument (Recommended)
Start the MCP server with the --swagger-url argument:
This automatically downloads and caches the Swagger definition. All tools will use this definition, and you won't need to provide swaggerFilePath in tool calls.
Method 2: Using getSwaggerDefinition Tool
Alternatively, you can ask the agent to get the Swagger file using the getSwaggerDefinition tool. Make sure you provide the URL for the swagger file, or at least a way to find it. This will download the file and save it locally with a hashed filename. The filename will automatically be added to a .swagger-mcp settings file in the root of your current solution.
Auto generated .swagger-mcp config file
When using the getSwaggerDefinition tool (Method 2 above), a .swagger-mcp file is automatically created:
This configuration file associates your current project with a specific Swagger API. We may use it to store more details in the future.
Once configured, you can reference the Swagger file path from this config file when calling tools. However, if you use the CLI --swagger-url argument (Method 1), this config file is optional as the Swagger definition is automatically loaded.
Improved MCP Tool Code Generator
The MCP tool code generator has been enhanced to provide more complete and usable tool definitions:
Key Improvements
Complete Schema Information: The generator now includes full schema information for all models, including nested objects, directly in the inputSchema.
Better Parameter Naming: Parameter names are now more semantic and avoid problematic characters like dots (e.g.,
taskRequestinstead oftask.Request).Semantic Tool Names: Tool names are now more descriptive and follow consistent naming conventions based on the HTTP method and resource path.
Support for YAML Swagger Files: The generator now supports both JSON and YAML Swagger definition files.
Improved Documentation: Generated tool definitions include comprehensive descriptions for all parameters and properties.
No External Dependencies: The generated code doesn't require importing external model files, making it more self-contained and easier to use.
AI-Specific Instructions: Tool descriptions now include special instructions for AI agents, helping them understand how to use the tools effectively.
Example Usage
To generate an MCP tool definition for an endpoint:
This will generate a complete MCP tool definition with full schema information for the POST /pets endpoint.
Note: If you started the server with --swagger-url, you can omit the swaggerFilePath parameter:
License
This project is licensed under the MIT License - see the LICENSE file for details.
MCP Prompts for AI Assistants
To help AI assistants use the Swagger MCP tools effectively, we've created a collection of prompts that guide them through common tasks. These prompts provide step-by-step instructions for processes like adding new endpoints, using generated models, and more.
Check out the PROMPTS.md file for the full collection of prompts.
Example use case: When asking an AI assistant to add a new endpoint to your project, you can reference the "Adding a New Endpoint" prompt to ensure the assistant follows the correct process in the right order.