
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.
README
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
Prerequisites
- Node.js (v14 or higher)
- npm or yarn
Installation
- Clone the repository:
git clone https://github.com/readingdancer/swagger-mcp.git
cd swagger-mcp
- Install dependencies:
npm install
- Create a
.env
file based on the.env.example
file:
cp .env.example .env
- Update the
.env
file.
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:
npm run build
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:
node build/index.js
Using the MCP Inspector
To run the MCP inspector for debugging:
npm run inspector
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:
node path/to/swagger-mcp/build/index.js
and then if needed, add the command line arguments as mentioned above. - Click "Add"
The Swagger MCP tools will now be available to the Cursor Agent in Composer.
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 definitionlistEndpointModels
: Lists all models used by a specific endpointgenerateModelCode
: Generates TypeScript code for a modelgenerateEndpointToolCode
: Generates TypeScript code for an MCP tool definition
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:
{
"method": "prompts/get",
"params": {
"name": "add-endpoint",
"arguments": {
"swaggerUrl": "https://petstore.swagger.io/v2/swagger.json",
"endpointPath": "/pets/{id}",
"httpMethod": "GET"
}
}
}
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
First ask the agent to get the Swagger file, make sure you give it the URL for the swagger file, or at least a way to find it for you, this will download the file and save it locally with a hashed filename, this filename will automatically be added to a .swagger-mcp
settings file in the root of your current solution.
Auto generated .swagger-mcp config file
SWAGGER_FILENAME = TheFilenameOfTheLocallyStoredSwaggerFile
This simple configuration file associates your current project with a specific Swagger API, we may use it to store more details in the future.
Once configured, the MCP will be able to find your Swagger definition and associate it with your current solution, reducing the number of API calls needed to get the project and tasks related to the solution you are working on.
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.,
taskRequest
instead 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:
import generateEndpointToolCode from './services/generateEndpointToolCode.js';
const toolCode = await generateEndpointToolCode({
path: '/pets',
method: 'POST',
swaggerFilePath: './petstore.json',
singularizeResourceNames: true
});
console.log(toolCode);
This will generate a complete MCP tool definition with full schema information for the POST /pets endpoint.
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.
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。