One Coding Agent Spent a Year Mocking MCP. It Just Made MCP a Core Feature.
Description and use
Pi initially rejected MCP due to high token costs, but by adopting Codemode—a sandboxed JavaScript execution model—migrated MCP into its core, reducing token usage and round‑trips.
Problem
Pi initially rejected the Model Context Protocol (MCP) because pre‑loading tool schemas consumed a large portion of the model’s context window, causing token waste and latency.
Outcome
Codemode reduced token consumption from 72 % to a rounding error, cut round‑trips from ten to one, and enabled repeatable, composable workflows, leading Pi to adopt MCP as a core feature.
Workflow
- 1. Agent receives user prompt. 2. Agent writes JavaScript code that calls MCP tools via the sandbox. 3. Code executes in QuickJS sandbox with all MCP tools available. 4. Only the final result is returned to the model’s context. 5. Agent outputs the result to the user.
Evidence
The standard way MCP worked was that every connected server pre‑loaded full schema definitions for all of its tools into your context window.
The Codemode pattern: the model writes JavaScript instead. That script executes inside a QuickJS sandbox running in Pi's harness, and the sandbox has the MCP tools available to it.
Fewer round trips. A chain of ten tool calls is one sandbox execution instead of ten model turns.
- Record date: 2026-10-01T04:08:07.777Z