Skip to main content
Glama
alohays

openai-tool2mcp

by alohays

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 不可阻挡的开源运动!

Related MCP server: OpenAI MCP Server

开发者的困境

人工智能开发人员目前面临着两个生态系统之间的艰难选择:

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 许可,可破解且可扩展

🚀 安装

# 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

🛠️ 快速入门

  1. 设置您的 OpenAI API 密钥

export OPENAI_API_KEY="your-api-key-here"
  1. 使用 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
  1. 与 Claude 桌面版一起使用

通过编辑 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 桌面应用配合使用:

  1. 使用pip install openai-tool2mcp安装软件包

  2. 配置您的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

🤝 贡献

欢迎社区贡献力量!您可以通过以下方式提供帮助:

  1. 分叉存储库

  2. 将您的 fork克隆到本地机器

  3. 为您的功能或错误修复创建一个分支

  4. 进行更改并提交

  5. 送到你的 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 社区致力于开发工具使用的开放标准

  • 所有帮助改进此项目的贡献者


⚠️ 项目状态

该项目正在积极开发中。在核心功能正常运行的同时,预计会频繁更新和改进。如果您遇到任何问题,请在我们的问题跟踪器上提交。


openai-tool2mcp 是更广泛的

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Latest Blog Posts

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/alohays/openai-tool2mcp'

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