MCP code execution enables 98.7% token savings through progressive tool disclosure and in-environment filtering¶
Insight: Using MCP servers as code-execution interfaces rather than direct tool calls reduces context pollution dramatically. Instead of loading all tool definitions upfront and processing intermediate results through the model, agents write code to load needed tools from a filesystem-structured MCP server, filtering large datasets in the execution environment before returning results to the model. This reduces token usage from 150,000 to 2,000 (98.7% saving) while enabling progressive disclosure, data filtering, privacy preservation, and state persistence across operations.
Detail: The tradeoff requires secure sandboxing and monitoring. Key principle: organize tools as filesystem structures enabling on-demand discovery rather than upfront loading. Large documents can be processed in execution environment rather than passed back to model for analysis.