OpenAPI转换MCP服务器

将OpenAPI规范转换为MCP服务器,将OpenAPI操作作为工具。

  • by JavaAIDev
  • Kotlin
  • 本地部署
  • 更新于
在 GitHub 查看 JavaAIDev/openapi-mcp-server

使用说明

OpenAPI MCP 服务器

将OpenAPI规范转换为MCP服务器,将OpenAPI操作作为工具。

这个MCP服务器使用stdio传输方式。

命令行接口(CLI)选项

在运行MCP服务器时,需要一个OpenAPI规范。它可以是文件路径,也可以是URL。

MCP服务器还提供了选项,用于过滤要作为MCP工具进行转换的操作。相同类型的过滤条件可以通过以下方式组合: OR而不同类型过滤条件则通过使用(某种方法/方式)进行组合 AND。

当前支持的过滤条件:

条件 CLI 选项 示例
HTTP 方法 --include-http-method --include-http-method=GET
路径 --include-path --include-path=/holidays
操作ID --include-operation-id --include-operation-id=Root
标签 --include-tag --include-tag=info

你可以运行这个JAR文件来查看命令行界面(CLI)的帮助信息。

Usage: openapi-mcp [-hV] [--header=<headers>[,<headers>...]]...
                   [--include-http-method=<includeHttpMethods>[,
                   <includeHttpMethods>...]]...
                   [--include-operation-id=<includeOperationIds>[,
                   <includeOperationIds>...]]... [--include-path=<includePaths>
                   [,<includePaths>...]]... [--include-tag=<includeTags>[,
                   <includeTags>...]]... [--query-param=<queryParams>[,
                   <queryParams>...]]... <openapiSpec>
Run OpenAPI MCP server
      <openapiSpec>   File path or URL of OpenAPI spec
  -h, --help          Show this help message and exit.
      --header=<headers>[,<headers>...]
                      Headers (comma separated with format a=b)
      --include-http-method=<includeHttpMethods>[,<includeHttpMethods>...]
                      Include operations with HTTP methods (comma separated)
      --include-operation-id=<includeOperationIds>[,<includeOperationIds>...]
                      Include operations with id (comma separated)
      --include-path=<includePaths>[,<includePaths>...]
                      Include operations with paths (comma separated)
      --include-tag=<includeTags>[,<includeTags>...]
                      Include operations with tags (comma separated)
      --query-param=<queryParams>[,<queryParams>...]
                      Query params (comma separated with format a=b)
  -V, --version       Print version information and exit.

如何跑步

独立的JAR文件

下载最新版本 发布JAR文件 并使用(相应的工具或环境)来运行它 java -jar。

java -jar openapi-mcp-server-0.1.4-all.jar https://api.apis.guru/v2/specs/exchangerate-api.com/4/openapi.json

集装箱

使用 Docker 或 Podman 来运行容器。

docker run -i ghcr.io/javaaidev/openapi-mcp-server https://api.apis.guru/v2/specs/exchangerate-api.com/4/openapi.json