
One MCP Server Burned 18,000 Tokens Before Your Agent Did Anything. Here's the Fix.
Cloud Platform EngineeringMCP was supposed to make AI agents more capable. It’s doing that — and creating a new class of invisible cost that most teams haven’t measured yet.
What Happened
Pi’s coding agent spent the better part of a year refusing to implement MCP support, despite the protocol becoming standard across developer tools. The reason, as Pi creator Mario Zechner explained, was concrete: a single connected MCP server — Chrome DevTools — consumed approximately 18,000 tokens from a 200,000-token context window before the agent took any action. That’s roughly 9% of available context, gone at initialization, every session.
MCP’s current architecture puts tool schemas — the full definitions of what each tool does and how to call it — directly into the model’s context window. A server with dozens of tools sends dozens of schema blocks. Multiple connected servers multiply the overhead. By the time an agent with three or four MCP servers has initialized, it’s burning a significant fraction of its context budget on tool declarations it may never use.
The Codemode Pattern
Pi’s solution, which it calls Codemode, inverts the architecture. When an MCP server is connected in Pi, its tool definitions are not injected into the prompt. Instead, the model is handed documentation — descriptions of what tools are available — and writes JavaScript to discover and call them as needed. That JavaScript executes inside a QuickJS sandbox running within Pi’s harness, where the MCP tools are available. Only the output of the JavaScript execution returns to the model context.
The efficiency is significant: Codemode caps tool declarations at a 3,000-token default budget, regardless of how many tools the server exposes. A developer can also control exposure per tool — some tools exposed directly, others hidden behind Codemode, others blocked entirely. The model only sees full tool schemas for the tools you decide are worth the context cost.
The underlying insight is that most MCP usage doesn’t require the model to know all tools at initialization. A coding agent working on a specific task needs a subset of available tools, and it can discover them dynamically through documentation + code generation rather than having every schema pre-loaded.
The So What
If you’re building agentic pipelines with multiple MCP servers, measure your context budget consumption before assuming your token costs are driven by task complexity. The overhead from schema injection can dominate context usage in multi-server setups, silently degrading effective context length and inflating per-task costs. The Codemode pattern is Pi-specific in implementation, but the architecture principle — don’t inject tool schemas you’re not actively using — is applicable to any MCP orchestration layer. If your platform team is standardizing on MCP for agent-to-tool connectivity, this tradeoff belongs in the design discussion before you build, not after you see the bills.
Source: The New Stack
Content created with AI assistance and reviewed for accuracy.
Join the conversation
Stack Insiders is our free community for readers who want to go deeper — share resources, ask questions, and connect with others across every vertical we cover.
Join Stack Insiders →