MCP Server for Swagger/OpenAPI documentation and API testing
npm install swagger-mcpA Model Context Protocol (MCP) server that provides tools for exploring and testing APIs through Swagger/OpenAPI documentation. This server automatically detects configuration files from multiple IDEs and provides comprehensive API interaction capabilities.
- ๐ Fetch and parse Swagger/OpenAPI documentation from any URL
- ๐งช Test API endpoints directly through the MCP interface
- ๐ Explore API schemas and understand data structures
- ๐ง Multi-IDE support - automatically detects config from VS Code, Cursor, Windsurf, and more
- ๐ Flexible authentication - supports API keys, basic auth, and bearer tokens
- โก Auto-discovery - can find documentation URLs automatically
Create an MCP configuration file in your IDE's configuration directory:
- VS Code: ~/.vscode/mcp.json or .vscode/mcp.json (in your project)
- Cursor: ~/.cursor/mcp.json or .cursor/mcp.json (in your project)
- Windsurf: ~/.windsurf/mcp.json or .windsurf/mcp.json (in your project)
- Any IDE: mcp.json (in your project root) or .mcp/config.json
#### Option 1: Using API Key
``json`
"swagger-mcp": {
"command": "npx",
"args": [
"-y",
"swagger-mcp@latest"
],
"env": {
"API_BASE_URL": "https://api.example.com",
"API_DOCS_URL": "https://api.example.com/swagger.json",
"API_KEY": "your-api-key-here"
}
}
#### Option 2: Using Username and Password
`json`
"swagger-mcp": {
"command": "npx",
"args": [
"-y",
"swagger-mcp@latest"
],
"env": {
"API_BASE_URL": "https://api.example.com",
"API_DOCS_URL": "https://api.example.com/swagger.json",
"API_USERNAME": "your-username",
"API_PASSWORD": "your-password"
}
}
- API_BASE_URL - Base URL for your API (e.g., https://api.example.com) [Required]API_DOCS_URL
- - Direct URL to Swagger/OpenAPI JSON/YAML (optional, will be auto-discovered)API_KEY
- - API key for authentication (used as Bearer token)API_USERNAME
- - Username for basic authenticationAPI_PASSWORD
- - Password for basic authentication
The server intelligently handles authentication:
1. For API requests: Uses API_KEY as Bearer token, falls back to Basic auth
2. For authentication endpoints: Auto-injects username/password credentials
3. Token management: Automatically stores and reuses tokens from login responses
4. Auto-refresh: Attempts to refresh tokens on 401 Unauthorized responses
Once configured, you can use the MCP server in your AI-powered editor to:
- Explore APIs: "Show me the available endpoints in this API"
- Test endpoints: "Test the POST /users endpoint with this data"
- Understand schemas: "Explain the User model structure"
- Debug API calls: "Help me troubleshoot this API request"
- Validate responses: "Check if this response matches the API schema"
The server automatically detects configuration files from:
- VS Code (.vscode/mcp.json).cursor/mcp.json
- Cursor ().windsurf/mcp.json
- Windsurf ()mcp.json
- Root directory ().mcp/config.json
- Alternative location ()
`bashClone the repository
git clone https://github.com/amrsa1/SwaggerMCP.git
cd SwaggerMCP
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.