Skip to main content
Glama

OpenAPI to Model Context Protocol (MCP)

OpenAPI 到模型上下文协议 (MCP)

回购规模最后提交未解决的问题Python 版本

OpenAPI-MCP 代理将 OpenAPI 规范转换为 MCP 工具,使 AI 代理无需自定义包装器即可访问外部 API!

OpenAPI-MCP

弥合人工智能代理与外部 API 之间的差距

OpenAPI 到模型上下文协议 (MCP) 代理服务器通过将 OpenAPI 规范动态转换为标准化的MCP 工具资源提示,弥合了 AI 代理与外部 API 之间的差距。这消除了对自定义 API 包装器的需求,从而简化了集成。


如果您发现它有用,请在 GitHub 上给它一个⭐!


主要特点

  • **FastMCP 传输:**针对stdio进行了优化,可与流行的 LLM 协调器一起开箱即用。
  • **OpenAPI 集成:**解析并注册 OpenAPI 操作作为可调用工具。
  • **资源注册:**自动将 OpenAPI 组件模式转换为具有定义 URI 的资源对象。
  • **提示生成:**根据 API 操作生成上下文提示,以指导 LLM 使用 API。
  • **OAuth2 支持:**通过客户端凭证流处理机器身份验证。
  • **JSON-RPC 2.0 支持:**完全兼容的请求/响应结构。
  • **自动元数据:**从 OpenAPI 规范中获取工具名称、摘要和模式。
  • **清理工具名称:**确保与 MCP 名称约束兼容。
  • **灵活的参数解析:**支持查询字符串(以“?”为前导)和多种 JSON 变体(包括带点和数字值的键)。
  • **增强的参数处理:**自动将参数转换为正确的数据类型。
  • **扩展工具元数据:**包括详细的参数信息和响应模式。

快速入门

安装

git clone https://github.com/gujord/OpenAPI-MCP.git cd OpenAPI-MCP pip install -r requirements.txt

LLM Orchestrator 配置

对于Claude DesktopCursorWindsurf ,使用下面的代码片段并相应地调整路径:

{ "mcpServers": { "petstore3": { "command": "full_path_to_openapi_mcp/venv/bin/python", "args": ["full_path_to_openapi_mcp/src/server.py"], "env": { "SERVER_NAME": "petstore3", "OPENAPI_URL": "https://petstore3.swagger.io/api/v3/openapi.json" }, "transport": "stdio" } } }

将此配置应用到以下文件:

  • 游标: ~/.cursor/mcp.json
  • 风帆冲浪: ~/.codeium/windsurf/mcp_config.json
  • Claude 桌面: ~/Library/Application Support/Claude/claude_desktop_config.json

full_path_to_openapi_mcp替换为您的实际安装路径。

环境配置

多变的描述必需的默认
OPENAPI_URLOpenAPI 规范的 URL是的-
SERVER_NAMEMCP 服务器名称openapi_proxy_server
OAUTH_CLIENT_IDOAuth 客户端 ID-
OAUTH_CLIENT_SECRETOAuth 客户端机密-
OAUTH_TOKEN_URLOAuth 令牌端点 URL-
OAUTH_SCOPEOAuth 范围api

工作原理

  1. **解析 OpenAPI 规范:**如果需要,使用httpxPyYAML加载 OpenAPI 规范。
  2. **注册操作:**提取 API 操作并生成具有适当输入和响应模式的 MCP 兼容工具。
  3. **资源注册:**自动将 OpenAPI 组件模式转换为具有分配 URI 的资源对象(例如, /resource/{name} )。
  4. **提示生成:**根据 API 操作创建上下文提示,以帮助 LLM 了解 API 的使用情况。
  5. **身份验证:**通过客户端凭证流支持 OAuth2 身份验证。
  6. **参数处理:**将参数转换为所需的数据类型,并支持灵活的查询字符串和 JSON 格式。
  7. **JSON-RPC 2.0 合规性:**确保工具交互的标准通信协议。

资源与提示

除了工具之外,代理服务器现在还会自动注册:

  • **资源:**从 OpenAPI 组件模式派生而来的资源对象通过定义的 URI(例如/resource/{name} )进行注册,以进行结构化数据处理。
  • **提示:**根据 API 操作生成上下文提示,为 LLM 提供使用指导,增强他们对可用端点的理解。

此扩展元数据通过提供全面的 API 上下文来改善集成。

OpenAPI-MCP

贡献

  • 分叉此存储库。
  • 创建新分支。
  • 提交拉取请求并清晰描述您的更改。

执照

MIT 许可证

如果您发现它有用,请在 GitHub 上给它一个⭐!

-
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.

通过将 OpenAPI 规范动态转换为标准化 MCP 工具来桥接 AI 代理和外部 API 的代理服务器,无需自定义集成代码即可实现无缝交互。

  1. 弥合人工智能代理与外部 API 之间的差距
    1. 主要特点
      1. 快速入门
        1. 安装
      2. LLM Orchestrator 配置
        1. 环境配置
      3. 工作原理
        1. 资源与提示
          1. 贡献
            1. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                An MCP server that generates AI agent tools from Postman collections and requests. This server integrates with the Postman API to convert API endpoints into type-safe code that can be used with various AI frameworks.
                Last updated -
                1
                7
                JavaScript
                MIT License
              • -
                security
                A
                license
                -
                quality
                A proxy server that enables AI assistants to run and interact with command-line applications like Expo through the Model Context Protocol (MCP), capturing logs and allowing keypress forwarding.
                Last updated -
                12
                6
                TypeScript
                MIT License
              • -
                security
                A
                license
                -
                quality
                A command-line tool that transforms any OpenAPI service into a Model Context Protocol (MCP) server, enabling seamless integration with AI agents and tools that support the MCP specification.
                Last updated -
                90
                2
                TypeScript
                MIT License
              • -
                security
                F
                license
                -
                quality
                A dynamic proxy that converts OpenAPI Specification (OAS) endpoints into Message Communication Protocol (MCP) tools, allowing AI agents to use existing REST APIs as if they were native MCP tools without manual implementation.
                Last updated -
                14
                TypeScript

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/gujord/OpenAPI-MCP'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server