Swagger API MCP server

Transforms Swagger/OpenAPI specifications into tools that enable interaction with any documented API through multiple authentication methods and real-time communication.
Back to servers
Provider
David Colley
Release date
Mar 13, 2025
Language
TypeScript
Stats
65 stars

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.

Prerequisites

  • Node.js v18 or higher
  • Yarn package manager
  • TypeScript

Installation

  1. Clone the repository:

    git clone https://github.com/dcolley/swagger-mcp.git
    cd swagger-mcp
    
  2. Install dependencies:

    yarn install
    
  3. Create environment configuration:

    cp .env.example .env
    
  4. 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"
        }
      }
    }
    

Starting the Server

Start the development server:

yarn dev

For production use, build and run:

yarn build
yarn start

Server Configuration

Swagger/OpenAPI Specification

You can provide your Swagger/OpenAPI specification in two ways:

  • Place a Swagger file in your project (e.g., swagger.json)
  • Provide a URL to the specification in your configuration

The server uses settings from the Swagger file first, falling back to config file values:

  • If the Swagger file contains a servers array, the first URL becomes the base URL
  • Security schemes defined in the Swagger file are used for authentication

Environment Variables

You can use these environment variables to configure the server:

  • PORT: Server port (default: 3000)
  • API_USERNAME: Username for API authentication
  • API_PASSWORD: Password for API authentication
  • API_TOKEN: API token for authentication
  • DEFAULT_API_BASE_URL: Default base URL for API endpoints
  • DEFAULT_SWAGGER_URL: Default Swagger specification URL

Authentication Methods

The server supports multiple authentication methods that can be configured in the config.json file:

Basic Auth

{
  "defaultAuth": {
    "type": "basic",
    "username": "your-username",
    "password": "your-password"
  }
}

Bearer Token

{
  "defaultAuth": {
    "type": "bearer",
    "token": "your-bearer-token"
  }
}

API Key

{
  "defaultAuth": {
    "type": "apiKey",
    "apiKey": "your-api-key",
    "apiKeyName": "X-API-Key",
    "apiKeyIn": "header"
  }
}

OAuth2

{
  "defaultAuth": {
    "type": "oauth2",
    "token": "your-oauth-token"
  }
}

API Endpoints

The MCP server exposes these endpoints:

  • GET /health - Check server health status
  • GET /sse - Establish Server-Sent Events connection
  • POST /messages - Send messages to the MCP server

Security Note

This server is intended for personal use only. Do not expose it to the public internet, especially if the underlying API requires authentication.

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later