Back to MCP directory
publicPublicdnsLocal runtime

openapi-to-mcp-server

一个将OpenAPI规范转换为MCP服务器配置的工具,支持参数自动映射和响应模板生成。

article

README

🚀 OpenAPI 转换为 MCP 配置工具

本工具能够将 OpenAPI 规范转换为 MCP 配置,支持多种文件格式,保留参数信息,还能生成便于 LLM 理解的响应模板,极大提升配置转换效率与质量。

✨ 主要特性

  • 路径转换:将 OpenAPI 的路径转换为 MCP 工具。
  • 文件格式支持:支持 JSON 和 YAML 格式的 OpenAPI 规范。
  • 生成配置:生成包含服务器和工具定义的 MCP 配置。
  • 保留参数描述:保留参数描述和类型信息。
  • 自动设置位置:根据 OpenAPI 参数位置自动设置 position 字段。
  • 支持多种参数类型:支持路径、查询、头、Cookie 和正文参数。
  • 生成响应模板:生成包含字段描述和改进格式的响应模板,便于 LLM 理解。
  • 可选规范验证:提供 OpenAPI 规范验证功能(默认关闭)。
  • 模板补丁支持:支持基于模板对生成配置进行自定义修改。

📚 详细文档

模板补丁功能

通过 --template 标志可以指定一个 YAML 文件,用于对生成的配置进行补丁式修改。这对于添加通用头、认证信息或其他自定义配置非常有用。

示例模板文件

server:
  config:
    apiKey: ""

tools:
  requestTemplate:
    headers:
      - key: Authorization
        value: "APPCODE {{.config.apiKey}}"
      - key: X-Ca-Nonce
        value: "{{uuidv4}}"

应用后操作

  1. 在服务器配置中添加 apiKey 字段。
  2. 将指定的头信息添加到所有工具的配置中。

使用方法

openapi-to-mcp --input api-spec.json --output mcp-server.yaml --server-name my-server --template template.yaml

模板中的占位符如 {{.config.apiKey}}"{{uuidv4}}" 不会在此工具中处理,而是直接保留在输出文件中,以便 MCP 服务器在运行时使用。

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