fix(mcp): omit image payloads from tool text (#848)

This commit is contained in:
NoxsMedia
2026-08-16 19:08:12 +08:00
committed by GitHub
parent 51532a2ea4
commit d388b697c5
2 changed files with 21 additions and 0 deletions

View File

@@ -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)"

View File

@@ -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 ────────────────────────────────────────────────