OpenAI工具MCP适配器
一个轻量级的桥梁,它将OpenAI内置工具(如网络搜索和代码解释器)包装为模型上下文协议(MCP)服务器,从而能够与Claude以及其他兼容MCP的模型一起使用。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"openai-tools": {
"args": [
"start",
"--transport",
"stdio",
"--tools",
"retrieval",
"code_interpreter"
],
"command": "openai-tool2mcp"
}
}
}
该服务需要配置环境变量:OPENAI_API_KEY
服务介绍
openai-tool2mcp
openai-tool2mcp 是一个轻量级、开源的桥梁,它将 OpenAI 强大的内置工具封装为 Model Context Protocol (MCP) 服务器。这使您能够使用高质量的 OpenAI 工具(如网络搜索和代码解释器)与 Claude 和其他 MCP 兼容模型一起工作。
- 🔍 在 Claude 应用中使用 OpenAI 的强大网络搜索
- 💻 在任何 MCP 兼容的大语言模型 (LLM) 中访问代码解释器功能
- 🔄 在 OpenAI 和 MCP 之间无缝协议转换
- 🛠️ 简单的 API 便于集成
- 🌐 完全兼容 MCP SDK
🔍 使用 Claude 应用的 OpenAI 搜索集成演示!🚀
https://github.com/user-attachments/assets/f1f10e2c-b995-4e03-8b28-61eeb2b2bfe9
OpenAI 曾试图将其强大的、针对大语言模型优化的工具限制在其自己的代理平台内,但他们无法阻止不可阻挡的 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 应用和其他 MCP 兼容客户端配合使用
- MCP SDK 兼容:使用官方的 MCP Python SDK
- 工具支持:
- 🔍 网络搜索
- 💻 代码解释器
- 🌐 网页浏览器
- 📁 文件管理
- 开源:MIT 许可证,可修改和扩展
🚀 安装
# Install from PyPI
pip install openai-tool2mcp
# Or install the latest development version
pip install git+https://github.com/alohays/openai-tool2mcp.git
# Recommended: Install uv for better MCP compatibility
pip install uv
前提条件
- Python 3.10+
- 具有访问 Assistant API 权限的 OpenAI API 密钥
- (推荐)uv 包管理器以实现 MCP 兼容性
🛠️ 快速开始
- 设置您的 OpenAI API 密钥:
export OPENAI_API_KEY="your-api-key-here"
- 启动带有 OpenAI 工具的 MCP 服务器:
# Recommended: Use uv for MCP compatibility (recommended by MCP documentation)
uv run openai_tool2mcp/server_entry.py --transport stdio
# Or use the traditional method with the 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
# Configure with OpenAI web search
config = ServerConfig(
openai_api_key="your-api-key",
tools=[OpenAIBuiltInTools.WEB_SEARCH.value]
)
# Create and start server with STDIO transport (for MCP compatibility)
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 environment variables
load_dotenv()
# Create a server with multiple tools
config = ServerConfig(
openai_api_key=os.environ.get("OPENAI_API_KEY"),
tools=[
OpenAIBuiltInTools.WEB_SEARCH.value,
OpenAIBuiltInTools.CODE_INTERPRETER.value
]
)
# Create and start the server with stdio transport for MCP compatibility
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 仓库
- 将您的 Fork 克隆到本地机器
- 为您的功能或错误修复创建一个分支
- 进行更改并提交它们
- 推送到您的 Fork 并提交一个拉取请求
请确保遵循我们的编码标准,并为任何新功能添加测试。
开发设置
# Clone the repository
git clone https://github.com/alohays/openai-tool2mcp.git
cd openai-tool2mcp
# Install in development mode
make install
# Run tests
make test
# Run linting
make lint
📄 许可证
该项目根据 MIT 许可证许可 - 详情请参阅 LICENSE 文件。
🙏 致谢
- OpenAI 团队提供的优秀工具和 API
- MCP 社区开发的工具使用的开放标准
- 所有帮助改进此项目的贡献者
⚠️ 项目状态
此项目正处于积极开发中。虽然核心功能已经可用,但预计会有频繁的更新和改进。如果您遇到任何问题,请在我们的 issue tracker 上提交。
openai-tool2mcp 是更广泛的 MCPortal 计划的一部分,旨在将 OpenAI 的工具与开源 MCP 生态系统连接起来。