openai-tool2mcp

Architecture Overview

This document provides a technical overview of how openai-tool2mcp bridges the OpenAI Assistant API with Model Context Protocol (MCP) servers.

System Architecture

openai-tool2mcp is designed as a protocol translation layer that sits between MCP-compatible clients and the OpenAI API:

sequenceDiagram
    participant Client as "MCP Client<br>(e.g., Claude App)"
    participant Server as "openai-tool2mcp Server"
    participant OAIAPI as "OpenAI Assistant API"

    Client->>Server: MCP Tool Request
    note over Server: Protocol Translation
    Server->>OAIAPI: OpenAI API Request
    OAIAPI->>Server: OpenAI Tool Response
    note over Server: Response Translation
    Server->>Client: MCP Tool Response

Protocol Translation

MCP to OpenAI Translation

MCP requests follow the Model Context Protocol specification, which defines a standard for tool usage. openai-tool2mcp maps these requests to OpenAI’s Assistant API format:

MCP Component OpenAI Equivalent
Tool ID Tool type
Tool parameters Tool parameters
Tool context Thread context
Instructions System prompt

OpenAI to MCP Translation

Responses from OpenAI tools are translated back to MCP format:

OpenAI Component MCP Equivalent
Tool output Tool response content
Error information Error messages
Metadata Tool context updates

Architectural Components

The system consists of the following main components:

1. MCP Server Interface

2. Protocol Translator

3. OpenAI Client

4. Tool Registry

Data Flow

  1. Request Phase:

    • MCP client sends a tool request to the server
    • Server validates the MCP request format
    • Protocol translator converts to OpenAI format
    • Request is sent to OpenAI API
  2. Processing Phase:

    • OpenAI processes the tool request
    • Tool executes the requested operation
    • Results are returned to OpenAI
  3. Response Phase:

    • OpenAI API returns tool output
    • Protocol translator converts to MCP format
    • MCP-formatted response is sent to client

Security Considerations

Tool-Specific Implementations

Web Search Tool

The Web Search tool maps MCP search requests to OpenAI’s built-in web search capability:

flowchart TD
    A[MCP Search Request] --> B{Protocol Translator}
    B --> C[OpenAI Web Search]
    C --> D[Search Results]
    D --> B
    B --> E[MCP Search Response]

Code Interpreter Tool

The Code Interpreter tool maps MCP code execution requests to OpenAI’s code interpreter:

flowchart TD
    A[MCP Code Execution Request] --> B{Protocol Translator}
    B --> C[OpenAI Code Interpreter]
    C --> D[Execution Results]
    D --> B
    B --> E[MCP Code Execution Response]

State Management

MCP and OpenAI have different approaches to maintaining state:

openai-tool2mcp handles this difference by:

  1. Creating OpenAI threads for each MCP session
  2. Persisting thread IDs and mapping them to MCP contexts
  3. Maintaining a session store for consistent tool state

Extension Points

The architecture is designed for extensibility: