Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 9, 2025

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

- Raise MAX_IMAGE_DATA_BYTES from 16KB to 8MB per image
  - AI SDK v5 properly converts media tool results to image blocks
  - Previous limit was unnecessarily restrictive for normal screenshots
  - New limit guards against pathological payloads while allowing typical images

- Tighten IPC integration tests for MCP image handling:
  - Add JPEG format test alongside existing PNG test
  - Assert no text parts contain data URIs or large base64 blobs
  - Verify model response includes 'example domain' to prove image was read
  - Ensures regression detection if SDK ever serializes images as text

_Generated with mux_
@ammar-agent ammar-agent force-pushed the mcp-context-exceeded-jpeg branch from cfba242 to 6e7475a Compare December 9, 2025 15:29
@ammario ammario merged commit bfdb809 into main Dec 9, 2025
18 of 20 checks passed
@ammario ammario deleted the mcp-context-exceeded-jpeg branch December 9, 2025 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants