RO

rustho/openapi-to-mcp

开发工具

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

29 stars 3 forks 质量 60 趋势 11ISC

从您现有的Swagger/OpenAPI规范中生成对AI友好的界面。该工具将API转换为模型控制协议(MCP)格式——用于通过大型语言控制工具和环境......

概览

根据您现有的 Swagger/OpenAPI 规范生成 AI 友好的接口。该工具将 API 转换为模型控制协议(MCP)格式——用于通过大型语言模型控制工具和环境。 该工具将OpenAPI/Swagger规范转换为模型控制协议(MCP)格式,使创建能够与API交互的AI代理变得轻松。 这是一个包含两个包的单仓库: - packages/core:主要的 OpenAPI 到 MCP CLI 工具和库- packages/playground:用于在浏览器中测试该工具的网页应用 - 📥 生成通用MCP。

概述(AI 翻译)

从你现有的Swagger/OpenAPI规范中生成对AI友好的界面。 该工具将API转换为模型控制协议(MCP)格式——用于通过大型语言模型控制工具和环境。

概述

该工具将OpenAPI/Swagger规范转换为模型控制协议(MCP)格式,使创建能够与API交互的AI代理变得轻松。

项目结构

这是一个包含两个包的单仓库:

  • packages/core:主要的 OpenAPI 到 MCP CLI 工具和库
  • packages/playground:用于在浏览器中测试该工具的网页应用

特色

  • 📥 从 OpenAPI/Swagger 文件生成通用 mcp.json
  • 🔄 从合适的GET端点自动提取状态模式
  • 📤 导出为多种格式:
  • 📜 带状态信息的提示指令
  • 🧱 带有getState action的JSON动作模板
  • 🔧 带有getState函数的函数模式(兼容OpenAI)
  • 🚀 MCP 服务器 TypeScript 文件,兼容 Claude Desktop
  • 🔌 独立执行器,用于 API 交互(兼容 LangChain/Web )
  • 📂 带有README的即插即用处理文件
  • 🔗 带有argsSchema和工具加载器的LangChain工具

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

README

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

OpenAPI-to-MCP

Generate AI-friendly interfaces from your existing Swagger/OpenAPI specs.
This tool converts APIs into Model Control Protocol (MCP) format — used to control tools and environments via large language models.

Overview

This tool converts OpenAPI/Swagger specifications into Model Control Protocol (MCP) format, making it easy to create AI agents that can interact with your APIs.

Project Structure

This is a monorepo containing two packages:

  • packages/core: The main OpenAPI-to-MCP CLI tool and library
  • packages/playground: A web application for testing the tool in your browser

Features

  • 📥 Generate universal mcp.json from OpenAPI/Swagger files
  • 🔄 Auto-extract state schema from suitable GET endpoints
  • 📤 Export to multiple formats:
    • 📜 Prompt instructions with state information
    • 🧱 JSON action templates with getState action
    • 🔧 Function schemas with getState function (OpenAI compatible)
    • 🚀 MCP server TypeScript file compatible with Claude Desktop
    • 🔌 Standalone executor for API interaction (LangChain/Web compatible)
    • 📂 Plug-and-play handler files with README
    • 🔗 LangChain tools with argsSchema and toolloader
    • 🔌 OpenAI plugin manifest with deployment instructions
  • 🧪 Simulation mode for testing without backend changes

Use Cases

  • Build Claude Desktop-compatible tools in seconds — Generate an MCP server that works directly with Claude
  • Turn any OpenAPI spec into LangChain/AutoGPT tools — Use the executor or LangChain tools for AI interfaces in any framework
  • Power AI interfaces for existing microservices — No backend changes required, works with existing APIs
  • Create ChatGPT plugins effortlessly — Generate OpenAI plugin manifests with proper schemas
  • Prototype AI agents with minimal setup — Use simulation mode to test AI interaction with your API
  • Create custom handler logic — Extend handlers with preprocessing, caching, or business logic

Installation

# Install globally
npm install -g openapi-to-mcp

# Or use directly with npx
npx openapi-to-mcp 

Usage

# Basic usage - generates all outputs
openapi-to-mcp path/to/swagger.yaml

# Specify output directory
openapi-to-mcp path/to/swagger.yaml -o ./custom-output

# Generate only specific formats
openapi-to-mcp path/to/swagger.yaml --prompt --functions

# Generate MCP server for Claude Desktop
openapi-to-mcp path/to/swagger.yaml --server --api-url https://your-api.com

# Generate standalone executor for any framework
openapi-to-mcp path/to/swagger.yaml --executor --api-url https://your-api.com

# Generate individual handler files for customization
openapi-to-mcp path/to/swagger.yaml --handlers --api-url https://your-api.com

# Generate LangChain tools for your API
openapi-to-mcp path/to/swagger.yaml --langchain --api-url https://your-api.com

# Generate OpenAI plugin manifest files
openapi-to-mcp path/to/swagger.yaml --openai-plugin --api-url https://your-api.com
在 GitHub 查看完整 README

安装

npx openapi-to-mcp <swagger-file>
新手?先看 mcpskill.org 教程 →