MCP-OpenAPI

by rmasters
MIT License
2

Integrations

  • Mentioned in the example configuration where a FastAPI server is running, and the README notes it uses a FastMCP server with registered tools

  • The package is available on PyPI as 'mcp-openapi'

  • Supports Swagger/OpenAPI specifications (versions 3.0 and 3.1) to expose HTTP methods as tools

MCP-OpenAPI

模型上下文协议服务器将 OpenAPI 规范中的 HTTP 方法作为工具公开。

[!警告] 这是一个概念证明,尚未经过全面测试和记录。

用法

每个 MCP-OpenAPI 服务器都公开一个 OpenAPI 规范的操作。您可以运行多个实例来公开多个规范。

此软件包可在 PyPI @ [ mcp-openapi ][pypi] 获取。您可以使用uvx mcp-openapi --openapi-url https://httpbin.org/spec.json (sse | stdio)启动服务器。

一个 Claude 配置示例(在使用端口 8000 运行fastapi dev tests/todos.py时):

{ "mcpServers": { "todos": { "command": "uvx", "args": [ "mcp-openapi", "--openapi-url=http://localhost:8000/openapi.json", "stdio" ] } } }

OpenAPI url 也可以作为环境变量MCP_OPENAPI_URL传递。

当以 SSE 运行时,您可以使用以下方式配置服务器:

  • --fastmcp-sse-host - 为 MCP 服务器提供服务的主机
  • --fastmcp-sse-port - MCP 服务器的端口

还有其他全局选项:

  • --fastmcp-debug - 为 MCP 服务器启用调试模式
  • --fastmcp-log-level - MCP 服务器的日志级别

这些也可以通过环境变量使用FASTMCP_前缀进行配置,例如FASTMCP_LOG_LEVEL=DEBUG

工作原理

  1. MCP-OpenAPI 服务器使用 OpenAPI 规范 URL 进行初始化。
  2. 服务器获取并解析 OpenAPI 规范,并将每个路径操作注册为一个工具。
  3. 使用注册的工具启动 FastMCP 服务器。
  4. 当客户端请求工具时,MCP 服务器向 API 发出 HTTP 请求并返回响应。

支持的 OpenAPI/Swagger 版本

Swagger 2.0OpenAPI 3.0OpenAPI 3.1
:x::重勾标记::重勾标记:

该软件包支持 JSON 和 YAML 格式的 OpenAPI 3.0 和 3.1 规范。

我们在底层使用openapi-parser ,它看起来非常全面,并且支持解析对外部规范的引用。

未来的配置选项

[!INFO] 这些仍有待实施。

限制端点

默认情况下,所有端点都以工具形式公开。您可以限制哪些端点公开:

  • 通过路径模式,
  • 通过 HTTP 方法,
  • 明确列出要公开的各个操作,
  • 使用 OpenAPI 标签选择路线。

处理 API 身份验证

MCP-OpenAPI 向目标 API 发出 API 请求 - 它可以使用全局身份验证令牌:

  • --auth-token - 承载令牌或 base64 格式的基本凭证,根据 OpenAPI 规范使用。

如果能够使用不同的身份验证令牌(例如,每个客户端用户)发出请求,但法学硕士 (LLM) 又无法看到这些令牌,那就太好了。有待确定。

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

MCP 服务器将 OpenAPI 规范中定义的 HTTP 方法公开为工具,从而能够通过模型上下文协议与 API 进行交互。

  1. Usage
    1. How it works
    2. Supported OpenAPI/Swagger versions
    3. Future configuration options
    4. Handling API authentication

Related MCP Servers

  • -
    security
    A
    license
    -
    quality
    MCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.
    Last updated -
    4
    3
    TypeScript
    MIT License
  • -
    security
    F
    license
    -
    quality
    A Model Context Protocol server implementation that enables connection between OpenAI APIs and MCP clients for coding assistance with features like CLI interaction, web API integration, and tool-based architecture.
    Last updated -
    9
    Python
    • Linux
    • Apple
  • -
    security
    A
    license
    -
    quality
    A server that enables interaction with any API that has a Swagger/OpenAPI specification through Model Context Protocol (MCP), automatically generating tools from API endpoints and supporting multiple authentication methods.
    Last updated -
    11
    TypeScript
    Apache 2.0
  • -
    security
    A
    license
    -
    quality
    A server that translates Model Context Protocol (MCP) tool callings to traditional HTTP API requests, allowing existing HTTP APIs to be integrated into MCP territory through configurable mappings.
    Last updated -
    Python
    Apache 2.0

View all related MCP servers

ID: ggsylex73e