OpenAPI MCP Server

Integrations

  • Uses environment variables for configuration management, allowing users to specify API endpoints, credentials, and other settings through a .env file.

  • Leverages Pydantic for data validation and parsing of API request/response models defined in OpenAPI specifications.

  • Enables interaction with RESTful APIs defined in Swagger/OpenAPI specifications, supporting GET, PUT, POST, and PATCH operations. The example demonstrates integration with the Swagger Petstore API, including operations like addPet, updatePet, and findPetsByStatus.

OpenAPI MCP 服务器

概述

  • 该项目将安装MCP - Model Context Protocol Server ,它提供配置的 REST API 作为 LLM 的上下文。
  • 使用此功能,我们可以使 LLM 与 RestAPI 交互并使用 LLM 提示执行 REST API 调用。
  • 目前我们支持HTTP API调用的GET/PUT/POST/PATCH

安装

  • 安装包
    pip install openapi_mcp_server
  • 在文件夹中创建 .env 文件,并设置OPENAPI_SPEC_PATHAPI_BASE_URL的最小值。示例文件可在此处获取。
  • 使用上述文件夹中的uv run openapi_mcp_server测试openapi_mcp_server服务器。

克劳德桌面

  • Claud Desktop 的配置详情
    { "mcpServers": { "openapi_mcp_server":{ "command": "uv", "args": ["run","openapi_mcp_server"] "env": { "DEBUG":"1", "API_BASE_URL":"https://petstore.swagger.io/v2", "OPENAPI_SPEC_PATH":"https://petstore.swagger.io/v2/swagger.json", "API_HEADERS":"Accept:application/json", "API_WHITE_LIST":"addPet,updatePet,findPetsByStatus" } } } }

配置

  • 可用环境变量列表
    • DEBUG :启用调试日志记录(可选,默认值为 False)
    • OPENAPI_SPEC_PATH :OpenAPI 文档的路径。(必需)
    • API_BASE_URL :API 请求的基本 URL。(必需)
    • API_HEADERS :API 请求中包含的标头(可选)
    • API_WHITE_LIST :白名单 operationId,列表格式为 [“operationId1”,“operationId2”] (可选)
    • API_BLACK_LIST :黑名单 operationId,列表格式为 [“operationId3”,“operationId4”] (可选)
    • HTTP_PROXY :HTTP 代理详细信息(可选)
    • HTTPS_PROXY :HTTPS 代理详细信息(可选)
    • NO_PROXY :无代理详细信息(可选)

贡献

欢迎投稿。
请随时提交拉取请求。

执照

该项目是根据 MIT 许可条款授权的。

Github 星标

附录

紫外线

mkdir -m777 openapi_mcp_server cd openapi_mcp_server uv init uv add mcp[cli] pydantic python-dotenv requests uv add --dev twine setuptools uv sync uv run openapi_mcp_server uv build pip install --force-reinstall --no-deps .\dist\openapi_mcp_server-*fileversion*.whl export TWINE_USERNAME="rahgadda" export TWINE_USERNAME="<<API Key>>" uv run twine upload --verbose dist/*

参考

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

模型上下文协议服务器使 LLM 能够通过自然语言提示与 REST API 调用交互并执行 REST API 调用,支持对配置的 API 执行 GET/PUT/POST/PATCH 操作。

  1. Overview
    1. Installation
      1. Claud Desktop
        1. Configuration
      2. Contributing
        1. License
          1. Github Stars
            1. Appendix
              1. UV
            2. Reference
              ID: 1lurw1271g