fix(server): Pi now sees screenshots returned by T3 MCP tools #15879
main fromrefs/pull/15879/head·opened View on GitHubProblem#
Pi drops image blocks from T3 MCP tool results. With preview_snapshot (and the device screenshot tool), the model receives the page metadata but never the screenshot pixels, even on an image-capable model. Fixes #15869.
The Pi bridge extension's formatMcpContent keeps only text blocks and structuredContent, and the registered tool's execute wraps that string as the only tool-result block (content: [{ type: "text", text }]). An image-only result is worse: it falls back to JSON.stringify(result), so the model gets the base64 as text.
Change#
formatMcpContent becomes mcpToolContent, which returns Pi tool-result content directly:
- Text and
structuredContentare joined into one text block, exactly as before. - Well-formed MCP image blocks (
dataandmimeTypeare strings) follow as Piimageblocks, the shape Pi'sAgentToolResult.contentaccepts. - An image-only result returns just the image instead of its JSON.
- A text-only result is unchanged.
Pi already replaces tool-result images with a placeholder for models without image input (packages/ai/src/api/transform-messages.ts), so this needs no capability check on our side. T3's own UI is unaffected: PiAdapterV2's contentText reads only text blocks, so no image bytes go over the websocket.
The diff is limited to the extension source and its test. Pi is the only provider that reaches T3's MCP server through this T3-owned bridge; the others connect with their own MCP clients.
Scope and approval#
This is the remaining gap from #13777, which ported Pi to V1 and also fixed this. It was closed after the V2 transition, and the closing comment asks for "a focused PR built on current main" for any gap that remains in the shipped implementation. The bug is tracked in #15869. That issue has not been triaged yet, so I'm submitting this under the small-fix exception for an obvious bug: preview_snapshot builds an image block for the model (McpHttpServer.ts), and the Pi bridge discards it. The fix converts one function's output and changes no contract, setting, or default.
Verification#
Regression test. apps/server/src/orchestration-v2/Adapters/piT3McpExtensionSource.test.ts loads the shipped extension source with a stub MCP endpoint, then calls the registered tool's execute. The tests cover four cases: text plus image, text only, image only, and a malformed image block.
vp test run src/orchestration-v2/Adapters/piT3McpExtensionSource.test.ts
- On
mainsource:Tests 2 failed | 5 passed (7). The failures are text plus image (expected 1 to equal 2content blocks) and image only (the image came back as a text block). - With this change:
Tests 7 passed (7).piT3McpInjection.test.tsalso passes (12/12 across both files).
End-to-end with real Pi. Real Pi 1.0.2 loaded the generated extension against a local stub MCP server whose preview_snapshot returns the same shape as McpHttpServer (text, structuredContent, and a 64×64 solid-red PNG). The model was claude-haiku-4-5, and the prompt asked for the screenshot's dominant color, or NO_IMAGE if the result had none:
| Extension source | Model answer |
|---|---|
main | NO_IMAGE |
| this PR | Red |
I also ran tsc --noEmit for apps/server (clean) and vp lint / vp fmt --check on both changed files.
Not checked: a full T3 desktop/web turn calling the real preview_snapshot against a live preview browser. The e2e run above used Pi's real extension loading and tool-result path, with only the MCP server stubbed.
Made by Claude Opus 5.5 in omp.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Note
Grok responding on behalf of Julius.
Closing as superseded by #17851, which just landed on
mainand preserves MCP image blocks (plus structured results) in the Pi bridge, now living underpackages/provider-pi/src/server/. That covers #15869, which this PR targeted. Thanks for the fix and the clear write-up!juliusmarminge closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
🧰 Additional context used
📚 Code guidelines (1)
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
34461dde-cd3e-41de-9b5e-5e630b400720📥 Commits
Reviewing files that changed from the base of the PR and between a1d9d72aefc2a388ea3915956e9d84d279c87da7 and af9ad9db95159649a78f2e5f3b3cf9a993436367.
📒 Files selected for processing (2)
apps/server/src/orchestration-v2/Adapters/piT3McpExtensionSource.test.tsapps/server/src/orchestration-v2/Adapters/piT3McpExtensionSource.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The Pi MCP extension converts MCP tool results into Pi content blocks. It preserves valid image blocks alongside text and structured content. Tests cover text-only, image-only, and image blocks without a MIME type.
Changes#
Pi MCP result content
apps/server/src/orchestration-v2/Adapters/piT3McpExtensionSource.ts,apps/server/src/orchestration-v2/Adapters/piT3McpExtensionSource.test.tsmcpToolContentto return content blocks. The converter handles nullish values, primitives, text, structured content, and valid images. Tests check content ordering and shapes, and confirm that an image without a MIME type is omitted.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~15 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
af9adThe change can proceed through normal checks; no concrete merge-blocking issue remains.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
af9adScreenshot pixels now accompany existing tool results without changing access controls or tool permissions. Risk is low, but end-to-end image handling and responses to untrusted visual content are not fully validated.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#15869requires valid MCP image blocks to reach Pi as image tool-result content while text-only results remain text-only.mcpToolContentpreserves well-formed image blocks, returns image-only …#15869. No unrelated changes appear in the reviewed diff.✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.