AO

abutbul/openapi-mcp-generator

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

28 stars 9 forks 质量 50 趋势 11MIT

一个 Python 工具,能够自动将兼容 OpenAPI(Swagger、ETAPI)的规范转换为功能齐全的模型上下文协议(MCP)服务器。

概览

一个 Python 工具,能够自动将 OpenAPI 规范转换为功能完整的模型上下文协议(MCP)服务器。生成支持 SSE/IO 通信协议、认证和全面错误处理的 Docker 支持实现。 - 🔄 OpenAPI 到 MCP 工具/资源转换 - 🐳 支持多阶段构建的 Docker 支持 - 🔐 多种认证方法 - ⚡ 异步操作和速率限制 - 📡 SSE/IO 通信协议 - 📦 模块化代码结构并支持包 生成器已被重构为一个正规的 Python 包,同时保持向后兼容性: 1. : generator.py 脚本依然完全正常 2.: 代码现在被拆分为重点模块 3.: 可以安装为正式的 Python 包 4.: 使用与模板完全相同的模板 5.: 保留所有 Docker 功能 你可以以任何你喜欢的方式使用这个工具:1. 直接运行 generator.py(原始方法) 2.

概述(AI 翻译)

一个 Python 工具,能够自动将 OpenAPI 规范转换为功能完整的模型上下文协议(MCP)服务器。生成支持 SSE/IO 通信协议、认证和全面错误处理的 Docker 支持实现。

主要特色:

  • 🔄 OpenAPI 到 MCP 工具/资源转换
  • 🐳 支持Docker和多阶段构建
  • 🔐 多重认证方法
  • ⚡ 异步操作与速率限制
  • 📡 SSE/IO通信协议
  • 📦 模块化代码结构,支持包

模块化代码结构

生成器已被重构为一个正规的 Python 包,同时保持向后兼容性:

  1. 原始入口点:generator.py脚本依然完全正常
  2. 模块化组织:代码现在被拆分为重点模块
  3. 软件包安装:可以作为正式的Python软件包安装
  4. 相同模板:在/templates目录中使用完全相同的模板
  5. Docker 支持:保留所有 Docker 功能

你可以以任何你喜欢的方式使用这个工具:

  1. 直接运行generator.py(原始方法)
  2. 作为包安装并使用 mcp-generator 命令

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

OpenAPI to MCP Server Generator

A Python tool that automatically converts OpenAPI specifications into fully functional Model Context Protocol (MCP) servers. Generates Docker-ready implementations with support for SSE/IO communication protocols, authentication, and comprehensive error handling.

Key features:

  • 🔄 OpenAPI to MCP tools/resources conversion
  • 🐳 Docker-ready with multi-stage builds
  • 🔐 Multiple authentication methods
  • ⚡ Async operations & rate limiting
  • 📡 SSE/IO communication protocols
  • 📦 Modular code structure with package support

Modular Code Structure

The generator has been refactored into a proper Python package while maintaining backward compatibility:

  1. Original Entry Point: The generator.py script still works exactly as before
  2. Modular Organization: Code is now split into focused modules
  3. Package Installation: Can be installed as a proper Python package
  4. Same Templates: Uses the exact same templates in the /templates directory
  5. Docker Support: Preserves all Docker functionality

You can use the tool in whatever way you prefer:

  1. Run generator.py directly (original approach)
  2. Install as a package and use mcp-generator command
  3. Use the module programmatically in your own Python code

For more details on the modular code structure, see MODULAR_REFACTORING.md.

Features

  • Convert OpenAPI specifications to MCP servers
  • Docker-ready implementation with multi-stage builds
  • Support for multiple authentication methods
  • Choice of SSE or IO communication protocols
  • Comprehensive error handling and logging
  • Built-in rate limiting and security features
  • Async operations for optimal performance
  • Extensive test suite with coverage reporting

Prerequisites

  • Python 3.10+
  • Docker (for running the generated server)
  • pip or uv (Python package manager)

Installation

From Source

# Clone the repository
git clone https://github.com/abutbul/openapi-mcp-generator.git
cd openapi-mcp-generator

# Install as a package (development mode)
pip install -e .

# Or using uv
uv venv
source .venv/bin/activate
uv pip install -e .

Using pip (once published)

pip install openapi-mcp-generator

Usage

# Using the original script (still works the same way)
python generator.py openapi.yaml --output-dir ./output --api-url https://api.example.com

# Using the new modular CLI tool after installation
mcp-generator openapi.yaml --output-dir ./output --api-url https://api.example.com

# Using the python module directly
python -m openapi_mcp_generator.cli openapi.yaml --output-dir ./output

Command Line Options

  • openapi_file: Path to the OpenAPI YAML file (required)
  • --output-dir: Output directory for the generated project (default: ‘.’)
  • --api-url: Base URL for the API
  • --auth-type: Authentication type (bearer, token, basic)
  • --api-token: API token for authentication
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →