Skip to content

fix(mcp): preserve image content blocks in tool results#9570

Closed
masterkain wants to merge 2 commits into
NousResearch:mainfrom
masterkain:fix-mcp-image-content-blocks
Closed

fix(mcp): preserve image content blocks in tool results#9570
masterkain wants to merge 2 commits into
NousResearch:mainfrom
masterkain:fix-mcp-image-content-blocks

Conversation

@masterkain

Copy link
Copy Markdown

Summary

  • preserve MCP image content blocks instead of collapsing image-only tool results to blank output
  • cache decoded image payloads and emit MEDIA: paths plus a media array in the tool result
  • add a regression test covering image-only CallToolResult.content

Problem

Some MCP servers return images as content blocks with data + mimeType and no text.

Hermes' MCP bridge only preserved text blocks and structuredContent, so image-only results were reduced to an empty string. In practice this made tools like Grafana panel image rendering appear blank even though the upstream MCP server had generated a valid PNG.

Root cause

In tools/mcp_tool.py, _make_tool_handler() iterated result.content but only appended blocks exposing .text.

Image blocks were ignored completely.

Fix

  • detect image blocks via data + mimeType
  • accept both plain base64 and data-URI payloads
  • decode and cache the image via cache_image_from_bytes(...)
  • return MEDIA:<path> in the text payload and expose a media list in the JSON result

Verification

  • pytest -q tests/tools/test_mcp_structured_content.py

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth labels Apr 27, 2026
@masterkain masterkain closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants