swagger-mcp-server

swagger-mcp-server

Converts any Swagger/OpenAPI specification into an MCP server, enabling AI assistants to intelligently query API endpoints, schemas, and generate code examples.

Category
访问服务器

README

🚀 Universal Swagger → MCP Server Converter

Stop wrestling with massive API docs in your AI assistant's context window. Start having intelligent conversations about any API.

CI License: MIT Python 3.11+ GitHub stars

MCP Compatible Cursor Claude VS Code


<div align="center">

⭐ Love this project? Give it a star! ⭐

<a href="https://github.com/salacoste/openapi-mcp-swagger/stargazers"> <img src="https://img.shields.io/github/stars/salacoste/openapi-mcp-swagger?style=for-the-badge&logo=github&logoColor=white&color=gold" alt="GitHub stars"/> </a>

🚀 Help us reach more developers who struggle with API integrations!
Your star makes this project more discoverable and motivates continued development.

⭐ Star this repo | 🍴 Fork it | 📢 Share it

</div>


💡 The Problem Every Developer Faces

You're building an integration with a complex API. The Swagger documentation is 2MB+ of JSON. Your AI assistant can only see tiny fragments at a time. You end up:

  • ❌ Copy-pasting documentation chunks into chat windows
  • ❌ Missing crucial schema relationships between endpoints
  • ❌ Getting outdated or incomplete code examples
  • ❌ Losing context when working across multiple API endpoints
  • ❌ Wasting hours on what should be simple integrations

✨ The Solution: Intelligent API Knowledge for AI

Transform any Swagger/OpenAPI specification into an intelligent MCP server that gives your AI assistant superpowers:

🎯 What Your AI Can Now Do:

# Instead of this painful workflow:
"Here's a 500KB Swagger file, please help me integrate..."
# Error: Context window exceeded

# You get this magical experience:
AI: "I need to create a user and get their profile data"
→ Instantly finds relevant endpoints: POST /users, GET /users/{id}
→ Generates complete TypeScript client with proper types
→ Includes error handling and authentication patterns
→ Shows example requests/responses for testing

🚀 From 0 to AI-Powered API Integration in 30 Seconds:

# 1. Convert any Swagger file to intelligent MCP server
swagger-mcp-server convert your-api.json

# 2. Connect to Cursor, Claude, or VS Code
# Your AI assistant now knows EVERYTHING about your API

# 3. Start building with superhuman API knowledge
"Create a React hook for user authentication with retry logic"
"Generate Python client for the payment endpoints"
"Show me all endpoints that return user data"

🌟 Real-World Impact:

  • ⚡ 10x Faster Integration: From hours to minutes for complex APIs
  • 🎯 Perfect Code Generation: AI understands full API context and relationships
  • 🔍 Instant API Discovery: Natural language search across any documentation size
  • 🛡️ Enterprise Ready: Works offline, handles massive APIs (10MB+), production deployment
  • 🔌 Universal Compatibility: Cursor, Claude, VS Code, or any MCP-compatible tool

Ready to supercharge your API development workflow? Jump to 🚀 Quick Start and experience the future of AI-assisted API integration.

📋 Table of Contents

✨ What is swagger-mcp-server?

swagger-mcp-server bridges the gap between API documentation and AI coding assistants. Instead of AI agents struggling with large API docs in their context window, they can now query specific information on-demand through the Model Context Protocol (MCP).

Key Benefits

  • 🔍 Intelligent Search: Find relevant endpoints using natural language queries
  • 📊 Schema Awareness: Get complete type information and relationships
  • 💻 Code Generation: Generate working examples in multiple languages
  • ⚡ Fast Responses: Sub-200ms search, optimized for AI agent workflows
  • 🔌 Easy Integration: Works with VS Code, Cursor, and custom AI tools
  • 🛡️ Production Ready: SSL, authentication, monitoring, and deployment guides

Use Cases

  • API Integration: Help AI assistants understand and use your APIs correctly
  • Documentation Search: Quickly find specific endpoints and schemas
  • Code Generation: Generate accurate API client code and examples
  • API Exploration: Discover API capabilities through intelligent search
  • Development Workflow: Integrate API knowledge into your coding environment

🚀 Quick Start

Step 1: Get Your Swagger JSON File

Before converting, you need to obtain the Swagger/OpenAPI JSON specification from any API documentation site:

🔍 Finding the Swagger JSON (Most Common Method)

  1. Visit any API documentation website (e.g., docs.example.com/api)
  2. Open Browser DevTools (F12 or Cmd/Ctrl + Shift + I)
  3. Go to Network tab and refresh the page
  4. Look for swagger.json or similar files in the network requests
  5. Click on the JSON file and copy the response
  6. Save it to your project in the swagger-openapi-data/ directory:
# Save the JSON content to the existing swagger-openapi-data directory
# Either copy-paste or download directly:
curl -o swagger-openapi-data/your-api.json "https://api.example.com/swagger.json"

# Or save manually by copying the JSON content and pasting it into:
# swagger-openapi-data/your-api.json

📋 Alternative Methods to Get Swagger JSON

Method 2: Direct URL Access

# Many APIs expose Swagger at common endpoints:
curl -o swagger-openapi-data/your-api.json "https://api.example.com/swagger.json"
curl -o swagger-openapi-data/your-api.json "https://api.example.com/v1/swagger.json"
curl -o swagger-openapi-data/your-api.json "https://api.example.com/docs/swagger.json"

Method 3: API Documentation Download Most API documentation sites have a "Download OpenAPI" or "Export JSON" button.

Method 4: Use Our Sample API (Already Included)

# We already include a sample Ozon Performance API for testing:
ls swagger-openapi-data/swagger.json  # 262KB Ozon API ready to use

Step 2: Installation

# Option 1: Install from source (recommended)
git clone https://github.com/salacoste/openapi-mcp-swagger.git
cd openapi-mcp-swagger

# Option 2: Install dependencies
pip install -r requirements.txt

# Option 3: Use standalone script (no installation required)
chmod +x scripts/standalone-mcp.py

Step 3: Convert & Start

# Convert your Swagger file to MCP server
swagger-mcp-server convert swagger-openapi-data/your-api.json --name your-api

# Or use the included sample API
swagger-mcp-server convert swagger-openapi-data/swagger.json --name ozon-api

# Start the MCP server
cd mcp-server-your-api  # or mcp-server-ozon-api
swagger-mcp-server serve

# 4. Test with AI agents or curl
curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"searchEndpoints","params":{"keywords":"user"}}'

Step 4: What Happens Next

🎉 Congratulations! Your API is now AI-ready. Here's what you get:

🧠 Intelligent API Knowledge

  • Complete endpoint mapping with search capability
  • Schema relationships preserved and queryable
  • Code examples generated on-demand in multiple languages
  • Context-aware responses for any API size

🤖 AI Assistant Integration

Connect to your favorite AI coding assistant:

For Cursor IDE:

# Add to .cursor-mcp/config.json
{
  "mcpServers": {
    "your-api": {
      "command": "swagger-mcp-server",
      "args": ["serve", "--port", "8080"]
    }
  }
}

For Claude/VS Code:

# Server will automatically integrate via MCP protocol
# Just point your AI assistant to: http://localhost:8080

✨ Start Building with AI Superpowers

Now you can ask your AI assistant:

"Create a TypeScript client for the user authentication endpoints"
"Show me all endpoints that handle payment processing"  
"Generate a React hook for real-time order status updates"
"What are the required fields for creating a new product?"

📖 Complete Quick Start: Follow our step-by-step Quick Start Tutorial to get your first MCP server running in 5 minutes with sample data.

🏗️ Architecture

The system consists of four main components:

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   AI Agent      │◄──►│   MCP Server     │◄──►│  Search Engine  │
│                 │    │                  │    │                 │
│ • Claude        │    │ • JSON-RPC API   │    │ • Endpoint Index│
│ • GPT-4         │    │ • Authentication │    │ • Schema Index  │
│ • Cursor        │    │ • Rate Limiting  │    │ • Full-Text     │
│ • VS Code       │    │ • Monitoring     │    │ • Relationships │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                                │
                                ▼
                       ┌──────────────────┐
                       │  Swagger Parser  │
                       │                  │
                       │ • Validation     │
                       │ • Schema Extract │
                       │ • Relationship   │
                       │ • Indexing       │
                       └──────────────────┘

Core Components

  • 🔍 Parser: Stream-based JSON parsing for large OpenAPI files (up to 10MB)
  • 💾 Storage: SQLite database with optimized search indexes and relationships
  • 🌐 Server: MCP protocol implementation with JSON-RPC over HTTP
  • 🔗 Search: Intelligent endpoint and schema search with relevance ranking
  • 💻 Examples: Multi-language code generation (cURL, JavaScript, Python, Go)

📖 Detailed Architecture: See docs/architecture/ for complete technical documentation and design decisions.

🔧 Development Setup

Prerequisites

  • Python 3.11 or higher (tested with Python 3.13.3)
  • Poetry (recommended for dependency management) or pip
  • pipx (for Poetry installation)
  • Git

System Dependencies

Install system dependencies first:

# macOS (using Homebrew)
brew install python@3.13 pipx

# Ubuntu/Debian
sudo apt update
sudo apt install python3.11-dev python3.11-venv python3-pip pipx

# Install Poetry
pipx install poetry

Local Development

  1. Clone and setup:

    git clone https://github.com/salacoste/openapi-mcp-swagger.git
    cd openapi-mcp-swagger
    
  2. Setup virtual environment and install dependencies:

    Option A: Using Poetry (Recommended):

    # Install all dependencies including dev dependencies
    poetry install --with dev
    
    # Activate virtual environment
    poetry shell
    

    Option B: Using pip with virtual environment:

    # Create virtual environment
    python3 -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
    # Upgrade pip
    pip install --upgrade pip
    
    # Install essential dependencies for development
    pip install pytest pytest-asyncio aiosqlite sqlalchemy structlog greenlet
    
    # Install optional dev dependencies
    pip install black isort flake8 mypy pytest-cov
    
  3. Verify installation:

    # Test import of main modules
    python -c "
    import sys; sys.path.append('src')
    from swagger_mcp_server.storage.migrations import Migration
    print('✅ Installation successful!')
    "
    
  4. Run tests:

    # With Poetry
    poetry run pytest src/tests/unit/test_storage/ -v
    
    # With pip/venv (make sure .venv is activated)
    PYTHONPATH=src python -m pytest src/tests/unit/test_storage/ -v
    
    # Run performance tests
    PYTHONPATH=src python -m pytest src/tests/performance/ -v
    
    # Run with coverage
    pytest --cov=src/swagger_mcp_server --cov-report=html
    
  5. Run linting:

    # Format code
    black src/
    isort src/
    
    # Check linting
    flake8 src/
    mypy src/swagger_mcp_server/
    

🧪 Testing

The project uses a comprehensive testing strategy:

  • Unit Tests: 80%+ coverage requirement, focused on individual components
  • Integration Tests: Full MCP server workflow testing
  • Performance Tests: Validation of response time requirements (<200ms search, <500ms schema)
  • Fixtures: Sample OpenAPI specifications for consistent testing

Running Tests

# All tests with coverage
poetry run pytest --cov=swagger_mcp_server --cov-report=html

# Unit tests only
poetry run pytest -m unit

# Integration tests only
poetry run pytest -m integration

# Performance/benchmark tests
poetry run pytest -m performance --benchmark-only

📁 Project Structure

swagger-mcp-server/
├── src/
│   ├── swagger_mcp_server/        # Main package
│   │   ├── parser/                # OpenAPI parsing
│   │   ├── storage/               # Database layer
│   │   ├── server/                # MCP implementation
│   │   ├── config/                # Configuration
│   │   └── examples/              # Code generation
│   └── tests/                     # Test suite
├── scripts/                       # Utility scripts
├── data/                          # Sample data
├── docs/                          # Documentation
├── .github/                       # CI/CD workflows
└── pyproject.toml                 # Project configuration

🔍 MCP Server Methods

The server implements three core MCP methods:

searchEndpoints(keywords, httpMethods)

Search for API endpoints using keywords and HTTP method filters.

// Example usage
const results = await mcpClient.call('searchEndpoints', {
  keywords: ['user', 'authentication'],
  httpMethods: ['GET', 'POST']
});

getSchema(componentName)

Retrieve complete schema definitions with dependencies.

const schema = await mcpClient.call('getSchema', {
  componentName: 'User'
});

getExample(endpoint, format)

Generate working code examples in multiple formats.

const example = await mcpClient.call('getExample', {
  endpoint: '/api/users',
  format: 'curl'  // 'curl', 'javascript', 'python'
});

📖 Complete API Reference: See docs/api/MCP_PROTOCOL.md for detailed protocol documentation, client libraries, and integration examples.

🔧 CLI Commands

Essential commands for everyday use:

# Convert Swagger to MCP server
swagger-mcp-server convert api.json --name my-api --port 8080

# Start server
swagger-mcp-server serve --config config.yaml

# Check server status
swagger-mcp-server status --all

# Configuration management
swagger-mcp-server config create production --output prod-config.yaml

# Setup and installation
swagger-mcp-server setup --verify

📖 Complete CLI Reference: See docs/reference/CLI_REFERENCE.md for all commands, options, and usage examples.

⚡ Performance Requirements

  • Search Response: < 200ms target, < 500ms maximum
  • Schema Retrieval: < 500ms target, < 1s maximum
  • File Processing: < 2s for files up to 5MB
  • Memory Usage: Process 10MB files within 2GB RAM
  • Concurrency: Support 100+ concurrent AI agent connections

📖 Performance Tuning: See docs/guides/PERFORMANCE.md for optimization strategies and scaling guidelines.

🤖 AI Tool Integrations

swagger-mcp-server works seamlessly with popular AI coding assistants:

VS Code + Continue

{
  "mcpServers": {
    "my-api": {
      "command": "swagger-mcp-server",
      "args": ["serve", "--config", "config.yaml"]
    }
  }
}

Cursor AI

{
  "mcp": {
    "servers": {
      "api-docs": "http://localhost:8080"
    }
  }
}

📖 Integration Guides: See docs/examples/integrations/ for complete setup instructions for VS Code, Cursor, and custom AI agents.

📝 Configuration

Basic Configuration

# config.yaml
server:
  host: localhost
  port: 8080

database:
  path: ./mcp_server.db

search:
  index_directory: ./search_index

logging:
  level: INFO
  console: true

Environment-Specific Configs

📖 Configuration Guide: See docs/guides/BASIC_CONFIG.md for configuration basics and docs/reference/CONFIGURATION.md for complete reference.

💡 Examples

Sample APIs

We provide realistic sample APIs for testing:

Quick Test

# Use our sample e-commerce API
swagger-mcp-server examples create-sample --type ecommerce --output sample-api.json
swagger-mcp-server convert sample-api.json --name demo
cd mcp-server-demo && swagger-mcp-server serve

📖 Examples Catalog: See docs/examples/swagger-files/README.md for all available sample APIs and use cases.

🤝 Contributing

We welcome contributions! Please see our contribution guidelines for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/my-feature
  3. Make your changes with tests
  4. Run the test suite: pytest
  5. Run linting: black src/ && flake8 src/
  6. Commit with conventional commits: git commit -m "feat: add new feature"
  7. Push and create a pull request

Code Quality Standards

  • Code Coverage: Minimum 80% (target 85%+)
  • Type Hints: Required for all public functions
  • Documentation: Comprehensive docstrings for public APIs
  • Performance: All changes must meet response time requirements
  • Security: No credentials in logs, input validation required

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🏷️ Version History

  • v0.1.0: Initial release with core parsing and MCP server functionality

🔧 Troubleshooting

Common Issues

Installation Problems:

# Python version issues
python --version  # Should be 3.9+

# Permission errors
pip install --user swagger-mcp-server

# Package conflicts
python -m venv venv && source venv/bin/activate

Runtime Issues:

# Port already in use
swagger-mcp-server serve --port 9000

# Database locked
swagger-mcp-server stop --all

# Search index corruption
rm -rf search_index/ && swagger-mcp-server serve

📖 Comprehensive Troubleshooting: See docs/troubleshooting/COMMON_ISSUES.md for detailed solutions to installation, configuration, and runtime problems.

📚 Complete Documentation

🚀 Getting Started

📖 Reference Documentation

💡 Examples and Integrations

🔧 Advanced Topics

🆘 Support and Troubleshooting

🛠️ Development

📖 Main Documentation Hub: See docs/README.md for the complete documentation index with detailed navigation.

🆘 Getting Help

Quick Help

Community Support

Before Reporting Issues

  1. ✅ Check Common Issues
  2. ✅ Search existing issues
  3. ✅ Try with minimal configuration
  4. ✅ Include system info and logs in your report

<div align="center">

🌟 Show Your Support 🌟

If this project helped solve your API integration challenges, please consider starring it!

<a href="https://github.com/salacoste/openapi-mcp-swagger/stargazers"> <img src="https://img.shields.io/github/stars/salacoste/openapi-mcp-swagger?style=for-the-badge&logo=star&logoColor=white&color=ffd700" alt="Star this repository"/> </a>

🎯 Why your star matters:

  • 📈 Increases visibility for developers facing similar challenges
  • 💪 Motivates continued development and new features
  • 🚀 Helps us prioritize community-requested improvements
  • 🤝 Shows appreciation for open-source work

Quick Actions:

⭐ Star • 🍴 Fork • 📋 Issues • 💬 Discuss

Thank you for being part of our community! 🙏

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选