mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 10:20:23 +08:00
fix(mcp): omit image payloads from tool text (#848)
This commit is contained in:
@@ -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)"
|
||||
|
||||
@@ -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 ────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user