You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 fix: raise MCP image guard to 8MB, add JPEG test matrix (#1034)
## Summary
Fixes MCP image handling that was unnecessarily restricting screenshots
to 16KB.
## Changes
- **Raise MAX_IMAGE_DATA_BYTES from 16KB to 8MB per image**
- AI SDK v5 properly converts `{ type: "media", mediaType, data }` tool
results into native image blocks for providers (Anthropic, OpenAI)
- Previous 16KB limit was based on a misunderstanding that images would
be tokenized as text
- New 8MB limit guards against pathological payloads while allowing
typical screenshots (~100KB–1MB)
- **Tighten IPC integration tests for MCP image handling:**
- Add JPEG format test alongside existing PNG test
- Assert no text parts contain `data:image` URIs or large base64 blobs
(≥10k chars)
- Verify model response includes "example domain" to prove the image was
actually read by the model
- Ensures regression detection if SDK ever serializes images as text
## Testing
- Unit tests: `bun test src/node/services/mcpResultTransform.test.ts` ✅
- Integration tests (PNG + JPEG): `TEST_INTEGRATION=1 bun x jest
tests/ipc/mcpConfig.test.ts -t "MCP image"` ✅
- Static checks: `make static-check` ✅
- All CI checks passing ✅
_Generated with `mux`_
@@ -92,14 +94,14 @@ export function transformMCPResult(result: MCPCallToolResult): unknown {
92
94
// Check if image data exceeds the limit
93
95
constdataLength=imageItem.data?.length??0;
94
96
if(dataLength>MAX_IMAGE_DATA_BYTES){
95
-
log.warn("[MCP] Image data too large, truncating",{
97
+
log.warn("[MCP] Image data too large, omitting from context",{
96
98
mimeType: imageItem.mimeType,
97
99
dataLength,
98
100
maxAllowed: MAX_IMAGE_DATA_BYTES,
99
101
});
100
102
return{
101
103
type: "text"asconst,
102
-
text: `[Image data too large to include in context: ${formatBytes(dataLength)}(${dataLength} bytes). The image was captured but cannot be displayed inline. Consider using a smaller viewport or requesting a specific region.]`,
104
+
text: `[Image omitted: ${formatBytes(dataLength)}exceeds per-image guard of ${formatBytes(MAX_IMAGE_DATA_BYTES)}. Reduce resolution or quality and retry.]`,
103
105
};
104
106
}
105
107
// Ensure mediaType is present - default to image/png if missing
0 commit comments