-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
What happened?
MCP tool results are not subject to any output truncation before being sent to the LLM context. Built-in tools like shell, grep, and ripGrep all apply truncation via truncateAndSaveToFile() (default: 25,000 chars / 1,000 lines), but MCP tool execution paths (executeWithDirectClient and executeWithCallableTool in mcp-tool.ts) return raw results directly without any size limiting.
This means an MCP server that returns a very large response (e.g., a database query tool returning thousands of rows, or a browser automation tool returning full page HTML) will flood the LLM context window, potentially degrading response quality, increasing token costs, and risking context overflow.
What did you expect to happen?
MCP tool results should be truncated using the same (or similar) logic as built-in tools, respecting truncateToolOutputThreshold and truncateToolOutputLines config values. When truncated, the full output should be saved to a temp file with a pointer, just like the shell tool does.
Client information
Client Information
N/A — this is a code-level bug found via source review, not runtime behavior.
Anything else we need to know?
The fix likely involves:
- Extracting text content from the MCP result parts after
transformMcpContentToParts() - Applying
truncateAndSaveToFile()(or a similar check) to any text parts that exceed the configured thresholds - Emitting
logToolOutputTruncatedtelemetry, consistent with the shell tool