openai-tool2mcp
一个轻量级的桥梁,将 OpenAI 的内置工具(如网页搜索和代码解释器)封装为模型上下文协议 (Model Context Protocol, MCP) 服务器,从而使它们能够与 Claude 和其他兼容 MCP 的模型一起使用。
README
openai-tool2mcp
openai-tool2mcp 是一个轻量级的开源桥梁,它将 OpenAI 强大的内置工具封装为模型上下文协议 (MCP) 服务器。它使您能够将高质量的 OpenAI 工具(如网络搜索和代码解释器)与 Claude 和其他 MCP 兼容的模型一起使用。
- 🔍 在 Claude App 中使用 OpenAI 强大的网络搜索
- 💻 在任何 MCP 兼容的 LLM 中访问代码解释器功能
- 🔄 OpenAI 和 MCP 之间的无缝协议转换
- 🛠️ 简单的 API,易于集成
- 🌐 与 MCP SDK 完全兼容
🔍 OpenAI 搜索与 Claude App 集成演示!🚀
https://github.com/user-attachments/assets/f1f10e2c-b995-4e03-8b28-61eeb2b2bfe9
OpenAI 试图将其强大的、针对 LLM 优化的工具锁定在他们自己的代理平台中,但他们无法阻止 MCP 不可阻挡的开源运动!
开发者的困境
AI 开发人员目前面临着在两个生态系统之间做出艰难选择:
graph TD
subgraph "Developer's Dilemma"
style Developer fill:#ff9e64,stroke:#fff,stroke-width:2px
Developer((Developer))
end
subgraph "OpenAI's Ecosystem"
style OpenAITools fill:#bb9af7,stroke:#fff,stroke-width:2px
style Tracing fill:#bb9af7,stroke:#fff,stroke-width:2px
style Evaluation fill:#bb9af7,stroke:#fff,stroke-width:2px
style VendorLock fill:#f7768e,stroke:#fff,stroke-width:2px,stroke-dasharray: 5 5
OpenAITools["Built-in Tools<br/>(Web Search, Code Interpreter)"]
Tracing["Advanced Tracing<br/>(Visual Debugging)"]
Evaluation["Evaluation Dashboards<br/>(Performance Metrics)"]
VendorLock["Vendor Lock-in<br/>⚠️ Closed Source ⚠️"]
OpenAITools --> Tracing
Tracing --> Evaluation
OpenAITools -.-> VendorLock
Tracing -.-> VendorLock
Evaluation -.-> VendorLock
end
subgraph "MCP Ecosystem"
style MCPStandard fill:#7dcfff,stroke:#fff,stroke-width:2px
style MCPTools fill:#7dcfff,stroke:#fff,stroke-width:2px
style OpenStandard fill:#9ece6a,stroke:#fff,stroke-width:2px
style LimitedTools fill:#f7768e,stroke:#fff,stroke-width:2px,stroke-dasharray: 5 5
MCPStandard["Model Context Protocol<br/>(Open Standard)"]
MCPTools["MCP-compatible Tools"]
OpenStandard["Open Ecosystem<br/>✅ Interoperability ✅"]
LimitedTools["Limited Tool Quality<br/>⚠️ Less Mature (e.g., web search, computer use) ⚠️"]
MCPStandard --> MCPTools
MCPStandard --> OpenStandard
MCPTools -.-> LimitedTools
end
Developer -->|"Wants powerful tools<br/>& visualizations"| OpenAITools
Developer -->|"Wants open standards<br/>& interoperability"| MCPStandard
classDef highlight fill:#ff9e64,stroke:#fff,stroke-width:4px;
class Developer highlight
openai-tool2mcp 通过让您在开放的 MCP 生态系统中使用 OpenAI 成熟、高质量的工具来弥合这一差距。
🌟 特性
- 易于设置:通过几个简单的命令即可启动并运行
- OpenAI 工具作为 MCP 服务器:将强大的 OpenAI 内置工具封装为符合 MCP 的服务器
- 无缝集成:与 Claude App 和其他 MCP 兼容的客户端配合使用
- MCP SDK 兼容:使用官方 MCP Python SDK
- 工具支持:
- 🔍 网络搜索
- 💻 代码解释器
- 🌐 网络浏览器
- 📁 文件管理
- 开源:MIT 许可,可破解和扩展
🚀 安装
# 从 PyPI 安装
pip install openai-tool2mcp
# 或者安装最新的开发版本
pip install git+https://github.com/alohays/openai-tool2mcp.git
# 推荐:安装 uv 以获得更好的 MCP 兼容性
pip install uv
前提条件
- Python 3.10+
- 具有访问 Assistant API 的 OpenAI API 密钥
- (推荐) 用于 MCP 兼容性的 uv 包管理器
🛠️ 快速开始
- 设置您的 OpenAI API 密钥:
export OPENAI_API_KEY="your-api-key-here"
- 使用 OpenAI 工具启动 MCP 服务器:
# 推荐:使用 uv 以获得 MCP 兼容性(MCP 文档推荐)
uv run openai_tool2mcp/server_entry.py --transport stdio
# 或者使用传统的 CLI 方法
openai-tool2mcp start --transport stdio
- 与 Claude for Desktop 一起使用:
通过编辑 claude_desktop_config.json 配置您的 Claude for Desktop 以使用该服务器:
{
"mcpServers": {
"openai-tools": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/your/openai-tool2mcp",
"run",
"openai_tool2mcp/server_entry.py"
]
}
}
}
配置文件位于:
- MacOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%AppData%\Claude\claude_desktop_config.json
💻 使用示例
基本服务器配置
# server_script.py
from openai_tool2mcp import MCPServer, ServerConfig, OpenAIBuiltInTools
# 配置 OpenAI 网络搜索
config = ServerConfig(
openai_api_key="your-api-key",
tools=[OpenAIBuiltInTools.WEB_SEARCH.value]
)
# 创建并启动具有 STDIO 传输的服务器(用于 MCP 兼容性)
server = MCPServer(config)
server.start(transport="stdio")
按照 MCP 的建议,使用 uv 运行它:
uv run server_script.py
用于 Claude Desktop 的 MCP 兼容配置
创建一个独立的脚本:
# openai_tools_server.py
import os
from dotenv import load_dotenv
from openai_tool2mcp import MCPServer, ServerConfig, OpenAIBuiltInTools
# 加载环境变量
load_dotenv()
# 创建一个具有多个工具的服务器
config = ServerConfig(
openai_api_key=os.environ.get("OPENAI_API_KEY"),
tools=[
OpenAIBuiltInTools.WEB_SEARCH.value,
OpenAIBuiltInTools.CODE_INTERPRETER.value
]
)
# 创建并启动具有 stdio 传输的服务器,以实现 MCP 兼容性
server = MCPServer(config)
server.start(transport="stdio")
配置 Claude Desktop 以使用 uv 运行此脚本:
{
"mcpServers": {
"openai-tools": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/your/project/folder",
"run",
"openai_tools_server.py"
]
}
}
}
📊 工作原理
该库充当 OpenAI Assistant API 和 MCP 协议之间的桥梁:
sequenceDiagram
participant Claude as "Claude App"
participant MCP as "MCP Client"
participant Server as "openai-tool2mcp Server"
participant OpenAI as "OpenAI API"
Claude->>MCP: User query requiring tools
MCP->>Server: MCP request
Server->>OpenAI: Convert to OpenAI format
OpenAI->>Server: Tool response
Server->>MCP: Convert to MCP format
MCP->>Claude: Display result
🔄 MCP SDK 集成
openai-tool2mcp 现在与 MCP SDK 完全兼容。 您可以通过以下方式将其与 Claude for Desktop 应用程序一起使用:
- 使用
pip install openai-tool2mcp安装软件包 - 配置您的
claude_desktop_config.json以包含:
{
"mcpServers": {
"openai-tools": {
"command": "openai-tool2mcp",
"args": [
"start",
"--transport",
"stdio",
"--tools",
"retrieval",
"code_interpreter"
]
}
}
}
配置文件位于:
- MacOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%AppData%\Claude\claude_desktop_config.json
🤝 贡献
我们欢迎社区的贡献! 您可以通过以下方式提供帮助:
- Fork 存储库
- Clone 您的 fork 到您的本地计算机
- 创建一个分支 用于您的功能或错误修复
- 进行更改 并提交它们
- Push 到您的 fork 并提交 pull request
请确保遵循我们的编码标准并为任何新功能添加测试。
开发设置
# 克隆存储库
git clone https://github.com/alohays/openai-tool2mcp.git
cd openai-tool2mcp
# 以开发模式安装
make install
# 运行测试
make test
# 运行 linting
make lint
📄 许可证
该项目已获得 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件。
🙏 鸣谢
- OpenAI 团队提供的出色工具和 API
- MCP 社区为开发工具使用的开放标准
- 所有帮助改进此项目的贡献者
⚠️ 项目状态
该项目正在积极开发中。 虽然核心功能有效,但预计会有频繁的更新和改进。 如果您遇到任何问题,请在我们的 issue tracker 上提交它们。
openai-tool2mcp 是更广泛的 MCPortal 计划的一部分,旨在将 OpenAI 的工具与开源 MCP 生态系统连接起来。
推荐服务器
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
AIO-MCP Server
🚀 集成了 AI 搜索、RAG 和多服务(GitLab/Jira/Confluence/YouTube)的一体化 MCP 服务器,旨在增强 AI 驱动的开发工作流程。来自 Folk。
Knowledge Graph Memory Server
为 Claude 实现持久性记忆,使用本地知识图谱,允许 AI 记住用户的信息,并可在自定义位置存储,跨对话保持记忆。
Hyperbrowser
欢迎来到 Hyperbrowser,人工智能的互联网。Hyperbrowser 是下一代平台,旨在增强人工智能代理的能力,并实现轻松、可扩展的浏览器自动化。它专为人工智能开发者打造,消除了本地基础设施和性能瓶颈带来的麻烦,让您能够:
https://github.com/Streen9/react-mcp
react-mcp 与 Claude Desktop 集成,能够根据用户提示创建和修改 React 应用程序。
MCP Atlassian
适用于 Atlassian Cloud 产品(Confluence 和 Jira)的 Model Context Protocol (MCP) 服务器。此集成专为 Atlassian Cloud 实例设计,不支持 Atlassian Server 或 Data Center 部署。
any-chat-completions-mcp
将 Claude 与任何 OpenAI SDK 兼容的聊天完成 API 集成 - OpenAI、Perplexity、Groq、xAI、PyroPrompts 等。