[Bug]: preview_snapshot can exhaust agent context with unbounded metadata #7410
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Start T3 Code with the built-in preview MCP tools available to a provider.
- Open a content-heavy page with a large accessibility tree or a large amount of visible text.
- Have the agent call
preview_snapshot. - Inspect the tool result and continue the thread with another prompt.
The server currently serializes the complete snapshot metadata into both the text content and structuredContent of the tool result.
Expected behavior#
preview_snapshot should keep the screenshot available while bounding the JSON metadata sent to the provider. If metadata must be omitted, the result should clearly say that it was truncated.
Actual behavior#
preview_snapshot forwards the full page metadata, including the accessibility tree, without a size limit. On large pages this can add hundreds of kilobytes to a single tool result and consume most of the thread's context window.
In the observed session, a later turn failed with an internal provider error after the oversized snapshot result entered the conversation.
This happens at the preview MCP response boundary, so it is not specific to one provider.
Impact#
Major degradation or frequent failure
Version or commit#
main @ 82b8a9380298509d68170961d9717be62836e490
Environment#
macOS, local desktop build, Kiro CLI via ACP. The oversized response is produced by the provider-independent preview MCP server.
Logs or stack traces#
Error: Internal error
at decodeJsonError (.../apps/server/dist/Schema-DNmPah4h.mjs:25100:111)
at decodeDefect (.../apps/server/dist/Schema-DNmPah4h.mjs:25136:54)
at sendTurn (.../apps/server/dist/bin.mjs:179228:26)
Screenshots, recordings, or supporting files#
No screenshot included. PR #7408 contains a focused regression test that sends an oversized snapshot through the MCP tool and verifies that the returned metadata is bounded.
Workaround#
Avoid preview_snapshot on content-heavy pages and use targeted preview_evaluate calls instead.
Proposed fix: #7408
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.