This MCP server connects to Swagger specifications and helps AI assistants generate the necessary models and tool definitions to interact with the specified APIs. It streamlines the creation of MCP servers by automating the interpretation of Swagger documentation.
git clone https://github.com/readingdancer/swagger-mcp.git
cd swagger-mcp
npm install
cp .env.example .env
Update the .env
file with appropriate values:
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)Build the application:
npm run build
Start the server after building:
node build/index.js
For debugging purposes, you can run the MCP inspector:
npm run inspector
To add this MCP server to Cursor:
node path/to/swagger-mcp/build/index.js
The Swagger MCP tools will now be available to the Cursor Agent in Composer.
The server provides guided workflows through prompts. For example, to use the "add-endpoint" prompt:
{
"method": "prompts/get",
"params": {
"name": "add-endpoint",
"arguments": {
"swaggerUrl": "https://petstore.swagger.io/v2/swagger.json",
"endpointPath": "/pets/{id}",
"httpMethod": "GET"
}
}
}
To start working with a Swagger API:
.swagger-mcp
settings file will be created in your project rootThe .swagger-mcp
file associates your project with a specific Swagger API:
SWAGGER_FILENAME = TheFilenameOfTheLocallyStoredSwaggerFile
The MCP tool code generator creates comprehensive tool definitions with:
import generateEndpointToolCode from './services/generateEndpointToolCode.js';
const toolCode = await generateEndpointToolCode({
path: '/pets',
method: 'POST',
swaggerFilePath: './petstore.json',
singularizeResourceNames: true
});
console.log(toolCode);
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.