Principle:AI QL Tuui MCP OpenAI Content Translation
| Knowledge Sources | |
|---|---|
| Domains | MCP, Content_Translation, Interoperability |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
A content translation pattern that converts between MCP content types (text, image, resource) and OpenAI-compatible message content formats.
Description
MCP and OpenAI use different content type schemas. MCP defines text, image (with mimeType + base64 data), and resource content types. OpenAI uses text and image_url (with a data URL). The translation pattern maps each MCP type to its OpenAI equivalent: text passes through directly, image becomes an image_url with a data:{mimeType};base64,{data} URL, and resource becomes a JSON-serialized text string. This enables MCP tool results to be consumed by OpenAI-compatible LLM APIs.
Usage
Use this principle when integrating MCP server tool results into OpenAI-compatible LLM chat completions, or when converting MCP sampling message content to OpenAI request format.
Theoretical Basis
The translation is a type-mapping function:
convert(mcpContent) → openaiContent:
case mcpContent.type:
'text' → { type: 'text', text: mcpContent.text } # identity
'image' → { type: 'image_url', image_url: { url: "data:{mime};base64,{data}" } }
'resource' → { type: 'text', text: JSON.stringify(mcpContent.resource) }
default → { type: 'text', text: JSON.stringify(mcpContent) }
The inverse direction (OpenAI → MCP for sampling) uses the same convertItem to translate MCP SamplingMessage content into OpenAI request messages.