mcp-for-swagger

akshay-harale/mcp-for-swagger

3.1

If you are the rightful owner of mcp-for-swagger and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server that dynamically exposes APIs based on Swagger/OpenAPI schema.

Swagger Server MCP

A Model Context Protocol (MCP) server that dynamically exposes APIs based on Swagger/OpenAPI schema.

Overview

This MCP server automatically generates tools for interacting with the Server's swagger APIs. It fetches the OpenAPI specification from the running server and creates MCP tools dynamically, allowing LLMs like Claude to manage tenants and users through natural language.

Features

  • Dynamic Tool Generation: Automatically creates MCP tools from OpenAPI/Swagger specs
  • Zero Configuration: No manual tool definitions needed
  • Auto-Updates: Tools update automatically when APIs change
  • Type-Safe: Input validation based on OpenAPI schemas
  • Path Parameter Handling: Automatic handling of URL path parameters
  • Request Body Mapping: Intelligent mapping of request bodies from schemas

Prerequisites

  • Node.js (v18 or higher)
  • Running Server on http://localhost:9000
  • Server with OpenAPI/Swagger enabled

Installation

Copy this code into the respective mcp server directory based on your application like claude /cline/copilot etc.

cd swagger-mcp
npm install
npm run build

Configuration

Environment Variables

  • API_BASE_URL: Base URL of the server (default: http://localhost:9000)
  • API_SPEC_PATH: Path to OpenAPI spec (default: /v3/api-docs)

Cline Integration

The server is configured in Cline's MCP settings file:

{
  "mcpServers": {
    "swagger-mcp": {
      "command": "node",
      "args": ["<C:\\Users\\username\\Documents\\Cline\\MCP>\\swagger-mcp\\build\\index.js"],
      "env": {
        "API_BASE_URL": "http://localhost:9000",
        "API_SPEC_PATH": "/v3/api-docs"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Claude Desktop Integration

Add to C:\Users\username\AppData\Roaming\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "swagger-mcp": {
      "command": "node",
      "args": ["C:\\Users\\username\\Documents\\Cline\\MCP\\swagger-mcp\\build\\index.js"],
      "env": {
        "API_BASE_URL": "http://localhost:9000",
        "API_SPEC_PATH": "/v3/api-docs"
      }
    }
  }
}

Available Tools

Once it is able to connect to the configured swagger it will be able to create a toold dynamically.

Usage Examples

With Cline or Claude Desktop

How It Works

  1. Startup: Server connects and fetches OpenAPI spec from server
  2. Parsing: Extracts all endpoints matching /api/**
  3. Tool Generation: Creates MCP tools with proper schemas for each endpoint
  4. Request Handling: Maps tool calls to HTTP requests with correct parameters
  5. Response: Returns formatted JSON responses to the LLM

Architecture

┌─────────────────┐
│   LLM (Claude)  │
└────────┬────────┘
         │ Natural Language
         ↓
┌─────────────────┐
│  MCP Protocol   │
└────────┬────────┘
         │ Tool Calls
         ↓
┌─────────────────┐
│ swagger-mcp     │ ← Fetches OpenAPI Spec
└────────┬────────┘
         │ HTTP Requests
         ↓
┌─────────────────┐
│     Server      │
│   Port 9000     │
└─────────────────┘

Development

Project Structure

swagger-mcp/
├── src/
│   └── index.ts          # Main MCP server implementation
├── build/                # Compiled JavaScript output
├── package.json          # Dependencies and scripts
├── tsconfig.json         # TypeScript configuration
└── README.md            # This file

Building

npm run build

Watching for Changes

npm run watch

Troubleshooting

MCP Server Not Connecting

  1. Verify OpenAPI spec is accessible:

    curl http://localhost:9000/v3/api-docs
    
  2. Check MCP server logs in Cline or Claude Desktop

Tools Not Appearing

  1. Restart Cline or Claude Desktop after configuration changes
  2. Ensure server is running before starting the MCP client
  3. Check that the build directory exists and contains index.js

API Errors

  • 403 Forbidden: Check if /api/** is excluded from authentication in server security config
  • 404 Not Found: Verify the API endpoint exists in the server
  • Connection Refused: Ensure server is running on the configured port

API Requirements

For this MCP server to work, your server must:

  1. Run on the configured port (default: 9000)
  2. Expose OpenAPI/Swagger documentation at /v3/api-docs
  3. Have /api/** endpoints accessible without authentication
  4. Include proper CORS headers for localhost connections

License

MIT

Contributing

This MCP server was created to simplify interaction with API in natural language interfaces. Contributions are welcome!

Support

For issues related to: