Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix: forward tool image artifacts over the chat MCP server (#1079)
Ruben Lütke0f6a2ca0a68a
diff --git a/dodaios/mcp/dodaios_tools_server.py b/dodaios/mcp/dodaios_tools_server.pyindex fbf5ac8e18..f3e2c7dc20 100644--- a/dodaios/mcp/dodaios_tools_server.py+++ b/dodaios/mcp/dodaios_tools_server.py@@ -218,6 +218,45 @@ def _render(result: Any) -> str:return str(output)+# Per-image byte budget for images handed back over MCP. Matches the+# screenshot tool's own cap, so a normal capture passes through untouched.+_MCP_IMAGE_MAX_BYTES: Final[int] = 500_000+# A runaway tool must not flood the model's context with pictures.+_MCP_MAX_IMAGES: Final[int] = 4+++def _image_contents(result: Any) -> list[tuple[str, str]]:+ """The image artifacts of a ToolResult as ``(mime, base64)`` pairs.++ Tools such as the screenshot tool return the picture as an artifact+ (``{"type": "image", "mime": ..., "data": <base64>}``) next to a short+ text output. Without this the MCP client only saw "Screenshot captured"+ and never the image (#1072). Anything that is not a well-formed image+ artifact is ignored, and every image is capped to a vision budget.+ """+ if result is None or not getattr(result, "success", False):+ return []+ artifacts = getattr(result, "artifacts", None)+ if not isinstance(artifacts, (list, tuple)):+ return []+ from dodaios.vision.image_budget import cap_image_b64++ images: list[tuple[str, str]] = []+ for artifact in artifacts:+ if len(images) >= _MCP_MAX_IMAGES:+ break+ if not isinstance(artifact, dict) or artifact.get("type") != "image":+ continue+ data = artifact.get("data")+ mime = artifact.get("mime") or artifact.get("mimeType") or "image/png"+ if not isinstance(data, str) or not data or not isinstance(mime, str):+ continue+ if not mime.startswith("image/"):+ continue+ images.append(cap_image_b64(mime, data, _MCP_IMAGE_MAX_BYTES))+ return images++def build_server() -> Any:"""A low-level MCP server bound to the live tool gateway.@@ -328,8 +367,13 @@ def build_server() -> Any:return types.CallToolResult(content=[types.TextContent(type="text", text=text)], isError=not success)+ content: list[Any] = [types.TextContent(type="text", text=_render(result))]+ content.extend(+ types.ImageContent(type="image", data=data, mimeType=mime)+ for mime, data in _image_contents(result)+ )return types.CallToolResult(- content=[types.TextContent(type="text", text=_render(result))],+ content=content,isError=not bool(getattr(result, "success", False)),)diff --git a/tests/unit/agent_chat/test_dodaios_harness.py b/tests/unit/agent_chat/test_dodaios_harness.pyindex 8d6defa83a..cc4a122d48 100644--- a/tests/unit/agent_chat/test_dodaios_harness.py+++ b/tests/unit/agent_chat/test_dodaios_harness.py@@ -293,3 +293,56 @@ def test_a_chat_without_a_ready_app_spawns_exactly_as_before(monkeypatch):)assert "--mcp-config" not in plan.argvassert "--append-system-prompt" not in plan.argv+++async def test_image_artifacts_reach_the_mcp_client_as_image_content():+ """A screenshot is useless to the chat if only "Screenshot captured" arrives (#1072)."""+ import base64++ import mcp.types as types++ png = base64.b64encode(b"\x89PNG\r\n\x1a\n" + b"\x00" * 32).decode("ascii")++ @dataclass+ class _ImageResult:+ success: bool = True+ output: Any = "Screenshot captured"+ error: str | None = None+ artifacts: tuple[Any, ...] = (+ {"type": "image", "mime": "image/png", "data": png},+ {"type": "file", "path": "C:/tmp/x.txt"},+ {"type": "image", "mime": "text/plain", "data": "aGVsbG8="},+ {"type": "image", "mime": "image/jpeg"},+ "not-a-dict",+ )++ class ImageGateway(_Gateway):+ async def execute(self, name, arguments, request):+ self.calls.append((name, arguments, request))+ return _ImageResult()++ runtime_refs.set_supervisor_tool_gateway(ImageGateway(names=("screenshot",)))+ instance = server.build_server()+ request = types.CallToolRequest(+ params=types.CallToolRequestParams(name="screenshot", arguments={})+ )+ response = await instance.request_handlers[types.CallToolRequest](request)+ content = response.root.content+ assert not response.root.isError+ assert content[0].type == "text" and content[0].text == "Screenshot captured"+ images = [c for c in content if c.type == "image"]+ assert len(images) == 1+ assert images[0].mimeType == "image/png" and images[0].data == png+++def test_failed_results_and_oversized_images_are_handled():+ @dataclass+ class _R:+ success: bool+ artifacts: Any = None++ assert server._image_contents(_R(False, ({"type": "image", "data": "x"},))) == []+ assert server._image_contents(_R(True, None)) == []+ many = tuple({"type": "image", "mime": "image/png", "data": "aGk="} for _ in range(10))+ assert len(server._image_contents(_R(True, many))) == server._MCP_MAX_IMAGES