From d388b697c5d533e626bef5eac4db9dfa72fc54c9 Mon Sep 17 00:00:00 2001 From: NoxsMedia <155662416+NoxsMedia@users.noreply.github.com> Date: Sun, 16 Aug 2026 19:08:12 +0800 Subject: [PATCH] fix(mcp): omit image payloads from tool text (#848) --- deeptutor/services/mcp/manager.py | 2 ++ tests/services/mcp/test_progress_reporting.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/deeptutor/services/mcp/manager.py b/deeptutor/services/mcp/manager.py index c9a40ea20..6d91fc512 100644 --- a/deeptutor/services/mcp/manager.py +++ b/deeptutor/services/mcp/manager.py @@ -557,6 +557,8 @@ class MCPConnectionManager: for block in result.content: if isinstance(block, types.TextContent): parts.append(block.text) + elif isinstance(block, types.ImageContent): + parts.append("[MCP image omitted]") else: parts.append(str(block)) return "\n".join(parts) or "(no output)" diff --git a/tests/services/mcp/test_progress_reporting.py b/tests/services/mcp/test_progress_reporting.py index 259f21492..c69183e82 100644 --- a/tests/services/mcp/test_progress_reporting.py +++ b/tests/services/mcp/test_progress_reporting.py @@ -208,6 +208,25 @@ async def test_progress_reaches_the_sink_end_to_end() -> None: assert result.content == "done" +@pytest.mark.asyncio +async def test_image_content_is_omitted_without_serializing_base64() -> None: + class _ImageSession(_Session): + async def call_tool(self, tool_name, arguments, progress_callback=None): # type: ignore[no-untyped-def] + from mcp import types + + return types.CallToolResult( + content=[ + types.TextContent(type="text", text="page image"), + types.ImageContent(type="image", data="QUJD", mimeType="image/jpeg"), + ] + ) + + result = await _adapter(MCPConnectionManager(), _ImageSession()).execute() + + assert result.content == "page image\n[MCP image omitted]" + assert "QUJD" not in result.content + + # ── why a connection failed ────────────────────────────────────────────────