Repository navigation
Description
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:
- The truncation should preserve the existing truncation marker convention (e.g.
[... truncated ...]) so the model knows content was cut. - This is a defence-in-depth measure; the guardrails checker timeout (guardrails: oversized content is skipped from inspection (maxContentBytes) — should compact-and-check or check in full #172 / ADR 0050) is the outer bound, but matching every other tool's output cap closes the largest unbounded ingress path at the source.
- Verify no MCP tool result legitimately exceeds 25 KiB in a way the truncation would break (if so, consider a larger MCP-specific cap or a config knob).
Scope
internal/adapter/mcp/tool.go— applytoolkit.Truncatein 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
MaxOutputBytesitself.
Ref: #172 (ADR 0050 — the security review that flagged this gap).
Activity
feat(guardrails): inspect oversized content instead of skipping (#172) (
feat(mcp): preserve typed content blocks, structured content, and res…
feat(mcp): preserve typed content blocks, structured content, and res…
feat(mcp): preserve typed content blocks, structured content, and res…
feat(mcp): preserve typed content blocks, structured content, and res…