Pi's Codemode Sandbox Cuts MCP Token Overhead by Two-Thirds
The coding agent now supports the Model Context Protocol without loading all tool definitions into the model's context window. By running tool discovery through a JavaScript sandbox, Pi 1.0 reduced prompt token consumption from 5,300 to 3,300 tokens.

For much of the past year, Pi's creator Mario Zechner kept the Model Context Protocol out of his coding agent despite its growing adoption across developer tools. His hesitation had a measurable basis: when Zechner tested the context overhead of popular browser-automation servers, Chrome DevTools MCP alone consumed roughly 18,000 tokens—approximately 9% of a 200,000-token context window—before the agent performed any actual work.
Pi now incorporates MCP as a native feature, but the implementation diverges from the standard approach. Rather than loading all server tool definitions into the model's prompt, Pi keeps them hidden and uses Codemode, its own code execution layer, to locate and invoke tools dynamically, returning only relevant results to the model.
The token cost problem
Zechner detailed the efficiency challenge in November of the previous year. Playwright MCP required approximately 13,700 tokens to describe its 21 tools—consuming 6.8% of a 200,000-token window—and each additional server introduced further overhead. Beyond sheer token consumption, Zechner identified a structural limitation: Results returned by an MCP server have to go through the agent's context to be persisted to disk or combined with other results.
Zechner's initial solution relied on Bash and custom scripts. Since the model already understood command-line interfaces, teaching it a new large tool interface seemed unnecessary. His CLI-based browser tools required only a 225-token README, and their output could be piped between commands, filtered or written to disk without routing through the model first. Extensions like pi-mcp-adapter eventually brought MCP support to Pi before version 1.0 made it a core feature.
A practical reversal
Earendil, which acquired Pi earlier this year, argues that MCP has matured sufficiently to warrant reconsideration. The company's explanation for the shift, however, suggests pragmatism rather than MCP's evolution alone. The reason we brought MCP into the core is not just about how MCP has changed, but also because we found that the changes it would require were generally useful, Earendil stated.
Pi was already employing the same architectural pattern with Jev, positioning Codemode—its implementation of the code mode design—between the model and its tools. MCP could adopt that same structure, exposing tools through Codemode rather than directly to the model.
How Codemode manages tool access
Codemode operates within a QuickJS sandbox that lacks Node APIs, file system access, network connectivity or timer functions. Scripts running in this environment can invoke Pi's tools and models, execute operations in parallel and process results before returning data to the model.
By default, Pi excludes an MCP server's tools from the model's context window. The system prompt receives only a single-line summary of each server, while the agent uses Codemode to discover and call the specific tools it requires.
Granular tool exposure settings
Developers can customize this behavior through the toolExposure parameter. On a single server, Pi can expose certain tools directly to the model, keep others behind Codemode or disable them entirely. A GitHub integration might expose search_code, place get_* operations behind Codemode and block delete_* functions.
Codemode has a 3,000-token default budget for tool declarations; anything beyond it stays discoverable. Pi 1.0 also reduced Codemode's overall footprint. According to release notes, a GPT-5.6 request using default tools and Codemode dropped from approximately 5,300 prompt tokens to 3,300 tokens after Pi condensed the Codemode description, relocated model API documentation outside the prompt and eliminated redundant declarations for tools that scripts could already access. MCP tools using default exposure settings do not consume any of that 3,000-token budget.
Pi 1.0 does not fully address Earendil's broader concerns about MCP, particularly around composability. Codemode provides Pi with a method to support the protocol while sidestepping the architectural approach Zechner originally objected to.