Skip to content

MCP tool results are not truncated to MaxOutputBytes (unlike every built-in tool) #178

Closed

Description

@JAORMX

The problem

Every built-in tool in mecatl truncates its output to MaxOutputBytes (25 KiB) via toolkit.Truncate(...) before returning a result — Read (internal/adapter/tools/read.go:145), Grep (grep.go:100), Glob (glob.go:94), Bash (bash.go:165), WebSearch (websearch.go:220), and the MCP resource/prompt helpers all do this.

MCP tool results do NOT. internal/adapter/mcp/tool.go (flattenContent, ~line 124-128) returns the raw MCP server response untruncated. A malicious or verbose MCP server can return arbitrarily large text that flows straight into the agent loop and (with guardrails enabled) into the Post-tool-use checker prompt — with no upstream size bound.

This was flagged by the security review of #172 (ADR 0050): with the maxContentBytes skip removed, an untruncated MCP result now drives a checker call over the full payload, bounded only by the 30s checker timeout. Under the read-parallel fan-out (N concurrent read-only tool calls per turn), N large MCP results drive N concurrent 30s checker calls — a cost-amplification vector.

Proposed change

Apply toolkit.Truncate (or the equivalent MaxOutputBytes cap) in internal/adapter/mcp/tool.go's flattenContent / remoteTool.Execute, so MCP tool results are subject to the same 25 KiB output cap as every built-in tool.

Considerations:

Scope

  • internal/adapter/mcp/tool.go — apply toolkit.Truncate in the result path.
  • Tests — verify MCP results are now truncated at the cap.
  • Docs — note the MCP output cap matches the built-in tool cap.

Out of scope

  • The concurrent read-batch amplification (ADR 0050's "known amplification" paragraph) — that's a broader fan-out bound, separate from the MCP truncation gap.
  • Changing MaxOutputBytes itself.

Ref: #172 (ADR 0050 — the security review that flagged this gap).

Activity

  1. added 2 commits that reference this issue on Jul 1, 2026
    87485c0
    009464e
  2. reopened this on Jul 1, 2026
  3. added a commit that references this issue on Jul 3, 2026
    8c2e076
  4. added a commit that references this issue on Jul 28, 2026
    21a4e4a
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