The Swagger MCP Server helps you work with APIs by ingesting Swagger/OpenAPI specifications and making them accessible through the Model Context Protocol (MCP). It automatically transforms API endpoints into usable MCP tools while supporting various authentication methods.
Clone the repository:
git clone https://github.com/dcolley/swagger-mcp.git
cd swagger-mcp
Install dependencies:
yarn install
Create environment configuration:
cp .env.example .env
Configure your server by creating or updating the config.json
file:
{
"server": {
"host": "localhost",
"port": 3000
},
"swagger": {
"url": "url-or-path/to/your/swagger.json",
"apiBaseUrl": "https://api.example.com",
"defaultAuth": {
"type": "apiKey",
"apiKey": "your-api-key",
"apiKeyName": "api_key",
"apiKeyIn": "header"
}
}
}
Start the development server:
yarn dev
For production use, build and run:
yarn build
yarn start
You can provide your Swagger/OpenAPI specification in two ways:
swagger.json
)The server uses settings from the Swagger file first, falling back to config file values:
servers
array, the first URL becomes the base URLYou can use these environment variables to configure the server:
PORT
: Server port (default: 3000)API_USERNAME
: Username for API authenticationAPI_PASSWORD
: Password for API authenticationAPI_TOKEN
: API token for authenticationDEFAULT_API_BASE_URL
: Default base URL for API endpointsDEFAULT_SWAGGER_URL
: Default Swagger specification URLThe server supports multiple authentication methods that can be configured in the config.json
file:
{
"defaultAuth": {
"type": "basic",
"username": "your-username",
"password": "your-password"
}
}
{
"defaultAuth": {
"type": "bearer",
"token": "your-bearer-token"
}
}
{
"defaultAuth": {
"type": "apiKey",
"apiKey": "your-api-key",
"apiKeyName": "X-API-Key",
"apiKeyIn": "header"
}
}
{
"defaultAuth": {
"type": "oauth2",
"token": "your-oauth-token"
}
}
The MCP server exposes these endpoints:
GET /health
- Check server health statusGET /sse
- Establish Server-Sent Events connectionPOST /messages
- Send messages to the MCP serverThis server is intended for personal use only. Do not expose it to the public internet, especially if the underlying API requires authentication.
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.