Skip to content

[BUG] Bound MCP tool results before adding them to model history #1253

Description

@zoomote

Problem

MCP servers can return arbitrarily large text payloads. Zoo Code currently allows those payloads to enter model-facing API history unchanged, so a single Git, browser, or other MCP result can exceed the context window and make condensation fail. This is the original failure reported in #648.

Scope

Bound MCP text results before they are added to model-facing history.

  • Apply a provider-agnostic model-facing size/token ceiling to MCP string and text-block results.
  • Preserve tool_use_id, error state, and valid tool call/result ordering.
  • Leave image and other non-text content behavior unchanged unless required to preserve a valid result shape.
  • Add a clear truncation marker containing the original and retained size.
  • Keep this change independent of future full-output storage or MCP resource-link support.

Acceptance criteria

  • A multi-megabyte MCP text result is bounded before the next model request.
  • Mixed MCP content retains valid non-text blocks and bounded text blocks.
  • Truncation preserves tool identifiers and provider-valid tool pairing.
  • Error results remain errors after truncation.
  • Focused tests cover string, structured text-block, mixed-content, and error results.

Out of scope

  • Native read_file budgeting
  • Condensation-input sanitization
  • Sliding-window recovery behavior
  • Full-output spill files or resource references
  • Aggregate budgeting across parallel tool calls

Estimate

1 story point. Independently mergeable and non-stacked.

Parent tracking issue: #648

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions