Skip to content

Conversation

@Kbediako
Copy link
Contributor

@Kbediako Kbediako commented Jan 24, 2026

What?

  • Render an MCP image output cell whenever a decodable image block exists in CallToolResult.content (including text-before-image or malformed image before valid image).

Why?

  • Tool results that include caption text before the image currently drop the image output cell.
  • A malformed image block can also suppress later valid image output.

How?

  • Iterate content and return the first successfully decoded image instead of only checking the first block.
  • Add unit tests that cover text-before-image ordering and invalid-image-before-valid.

Before

let image = match result {
    Ok(mcp_types::CallToolResult { content, .. }) => {
        if let Some(mcp_types::ContentBlock::ImageContent(image)) = content.first() {
            // decode image (fails -> None)
        } else {
            None
        }
    }
    _ => None,
}?;

After

let image = result
    .as_ref()
    .ok()?
    .content
    .iter()
    .find_map(decode_mcp_image)?;

Risk / Impact

  • Low: only affects image cell creation for MCP tool results; no change for non-image outputs.

Tests

  • just fmt
  • cargo test -p codex-tui
  • Rerun after branch update (2026-01-27): just fmt, cargo test -p codex-tui

Fixes #9814

@Kbediako Kbediako marked this pull request as ready for review January 24, 2026 12:47
@Kbediako Kbediako changed the title fix: render MCP image outputs regardless of ordering Fix: Render MCP image outputs regardless of ordering Jan 24, 2026
@joshka-oai joshka-oai self-assigned this Jan 27, 2026
Add an image_scenario tool to the rmcp stdio test server so the Codex
TUI can be exercised against mixed/invalid image blocks (text+image,
invalid base64, invalid bytes, multiple images).

Also document the TUI decode path
(try_new_completed_mcp_tool_call_with_image_output, decode_mcp_image) to
clarify that we render the first decodable image and skip failures until
a valid image is found.
@joshka-oai
Copy link
Collaborator

Added a small set of extra MCP helpers to make it possible to manually test this in b9e3749

@joshka-oai joshka-oai enabled auto-merge (squash) January 27, 2026 21:03
@joshka-oai
Copy link
Collaborator

Manual testing: MCP image tool result rendering (Codex TUI)

Build the rmcp stdio test server binary:

cd codex-rs
cargo build -p codex-rmcp-client --bin test_stdio_server

Register the server as an MCP server (absolute path to the built binary):

codex mcp add mcpimg -- /Users/joshka/code/codex-pr-review/codex-rs/target/debug/test_stdio_server

Then in Codex TUI, ask it to call:

  • mcpimg.image_scenario({"scenario":"image_only"})
  • mcpimg.image_scenario({"scenario":"text_then_image","caption":"Here is the image:"})
  • mcpimg.image_scenario({"scenario":"invalid_base64_then_image"})
  • mcpimg.image_scenario({"scenario":"invalid_image_bytes_then_image"})
  • mcpimg.image_scenario({"scenario":"multiple_valid_images"})
  • mcpimg.image_scenario({"scenario":"image_then_text","caption":"Here is the image:"})
  • mcpimg.image_scenario({"scenario":"text_only","caption":"Here is the image:"})

Expected:

  • You should see an extra history cell: "tool result (image output)" when the
    tool result contains at least one decodable image block (even if earlier
    blocks are text or invalid images).

@joshka-oai joshka-oai merged commit 337643b into openai:main Jan 27, 2026
26 of 32 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: TUI drops MCP image output when text precedes image

2 participants