OpenAPI 到模型上下文协议 (MCP)
OpenAPI-MCP 代理将 OpenAPI 规范转换为 MCP 工具,使 AI 代理无需自定义包装器即可访问外部 API!
弥合人工智能代理与外部 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 变体(包括带点和数字值的键)。
- **增强的参数处理:**自动将参数转换为正确的数据类型。
- **扩展工具元数据:**包括详细的参数信息和响应模式。
快速入门
安装
LLM Orchestrator 配置
对于Claude Desktop 、 Cursor和Windsurf ,使用下面的代码片段并相应地调整路径:
将此配置应用到以下文件:
- 游标:
~/.cursor/mcp.json
- 风帆冲浪:
~/.codeium/windsurf/mcp_config.json
- Claude 桌面:
~/Library/Application Support/Claude/claude_desktop_config.json
将
full_path_to_openapi_mcp
替换为您的实际安装路径。
环境配置
多变的 | 描述 | 必需的 | 默认 |
---|---|---|---|
OPENAPI_URL | OpenAPI 规范的 URL | 是的 | - |
SERVER_NAME | MCP 服务器名称 | 不 | openapi_proxy_server |
OAUTH_CLIENT_ID | OAuth 客户端 ID | 不 | - |
OAUTH_CLIENT_SECRET | OAuth 客户端机密 | 不 | - |
OAUTH_TOKEN_URL | OAuth 令牌端点 URL | 不 | - |
OAUTH_SCOPE | OAuth 范围 | 不 | api |
工作原理
- **解析 OpenAPI 规范:**如果需要,使用
httpx
和PyYAML
加载 OpenAPI 规范。 - **注册操作:**提取 API 操作并生成具有适当输入和响应模式的 MCP 兼容工具。
- **资源注册:**自动将 OpenAPI 组件模式转换为具有分配 URI 的资源对象(例如,
/resource/{name}
)。 - **提示生成:**根据 API 操作创建上下文提示,以帮助 LLM 了解 API 的使用情况。
- **身份验证:**通过客户端凭证流支持 OAuth2 身份验证。
- **参数处理:**将参数转换为所需的数据类型,并支持灵活的查询字符串和 JSON 格式。
- **JSON-RPC 2.0 合规性:**确保工具交互的标准通信协议。
资源与提示
除了工具之外,代理服务器现在还会自动注册:
- **资源:**从 OpenAPI 组件模式派生而来的资源对象通过定义的 URI(例如
/resource/{name}
)进行注册,以进行结构化数据处理。 - **提示:**根据 API 操作生成上下文提示,为 LLM 提供使用指导,增强他们对可用端点的理解。
此扩展元数据通过提供全面的 API 上下文来改善集成。
贡献
- 分叉此存储库。
- 创建新分支。
- 提交拉取请求并清晰描述您的更改。
执照
如果您发现它有用,请在 GitHub 上给它一个⭐!
This server cannot be installed
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 的代理服务器,无需自定义集成代码即可实现无缝交互。
Related MCP Servers
- AsecurityAlicenseAqualityAn 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 -17JavaScriptMIT License
- -securityAlicense-qualityA 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 -126TypeScriptMIT License
- -securityAlicense-qualityA 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 -902TypeScriptMIT License
- -securityFlicense-qualityA 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 -14TypeScript