Skip to content

[Bug]: preview_snapshot can exhaust agent context with unbounded metadata #7410

Description

@devhims

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

  1. Start T3 Code with the built-in preview MCP tools available to a provider.
  2. Open a content-heavy page with a large accessibility tree or a large amount of visible text.
  3. Have the agent call preview_snapshot.
  4. 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 @ 82b8a93

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions