Back to MCP directory
publicPublicdnsLocal runtime

openapi-to-mcp-converter

一个将OpenAPI规范自动转换为MCP服务器实例的工具

article

README

🚀 OpenAPI 到 MCP 服务器转换器

本工具可自动将 OpenAPI 规范转换为 Model Context Protocol (MCP) 服务器实例,能有效提升从 OpenAPI 规范到 MCP 服务器实例的转换效率,节省开发时间。

🚀 快速开始

先决条件

  • Node.js 18+
  • TypeScript 5.x

基本使用方法

安装包:

npm install openapi-mcp-converter

运行本地标准输入输出 (stdio) MCP 服务器:

import fs from 'fs';
import { OpenApiMCPSeverConverter } from '../index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import path from 'path';
import { fileURLToPath } from 'url';

const openApiDoc = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), 'openapi.json'), 'utf8'));

const converter = new OpenApiMCPSeverConverter(openApiDoc, { timeout: 100000 });
const server = converter.getServer();
console.log(JSON.stringify(converter.getMcpTools(), null, 2));
console.log(JSON.stringify(converter.getTools(), null, 2));
async function runServer() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.log("GitHub MCP 服务器在标准输入输出上运行");
}

runServer().catch((error) => {
  console.error("主程序中出现致命错误:", error);
  process.exit(1);
});

运行示例

npm run test  # 执行示例测试用例

✨ 主要特性

  • 🚀 自动化转换:自动解析 OpenAPI 3.0 规范。
  • 🛠 类型安全:基于 TypeScript 的强类型验证。
  • 🔄 请求代理:自动处理工具调用参数映射。

📚 详细文档

项目结构

/openapi-to-mcp
├── dist/            # 编译输出
├── src/             # 源代码
│   ├── example/     # 示例配置
│   └── index.ts     # 核心实现
├── package.json
└── tsconfig.json

构建命令

npm run build    # 生产构建
npm run watch    # 开发模式监视

📄 许可证

本项目采用 MIT 许可证

Node.js 版本 TypeScript 版本 许可证: MIT

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client