Problem#
preview_snapshot forwards Chrome's full accessibility tree to the provider. On large pages, this can add hundreds of kilobytes of JSON to one tool result and consume most of the thread's context window.
Fix#
Cap snapshot metadata at 64 KB. If it exceeds the limit, omit the accessibility tree and mark the result as truncated. If the remaining fields are still too large, return a compact page summary. Normal snapshots are unchanged.
Added a regression test that sends an oversized snapshot through the MCP tool and verifies that the returned metadata stays within the limit.
Validation#
vp test run apps/server/src/mcp/McpHttpServer.test.ts
vp run --filter t3 typecheck
- Targeted lint and formatting checks
Implemented with GPT-5 via Codex desktop.
Note
Bound preview snapshot metadata to 64,000 bytes in preview_snapshot tool#
- Adds a
previewSnapshotMetadata helper in McpHttpServer.ts that serializes snapshot metadata (excluding screenshot data) and truncates it if it exceeds 64,000 bytes.
- When over the limit, it first drops
accessibilityTree and marks truncation with reason metadata_size_limit; if still over, it falls back to truncating strings (visibleText to 8,000 chars, URL/title) and clearing list fields.
- The
preview_snapshot handler now uses this helper for both the text content (serialized JSON) and structuredContent (bounded metadata object).
- Behavioral Change: oversized snapshot responses will now be truncated with truncation metadata rather than returned as-is.
Macroscope summarized 3cdc4c5.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
c8af7b0b-054e-429a-b1f6-470394f1cc1bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share