Anyone scaling Model Context Protocol connectors past a handful of tools hits the same wall: schema bloat and multi-turn round-trip tax. Over the past year, both server builders and harness teams converged on a major architectural shift known as MCP Code Mode in Claude Code and Cloudflare. Instead of stuffing hundreds of JSON tool definitions into the prompt and reading every intermediate API payload line by line, the model writes a short JavaScript or Python program that calls tools as typed functions inside a sandbox and returns only the final shaped answer. Understanding where Code Mode saves 99 percent of context tokens, and what it quietly gives up on operational records, is essential for enterprise AI architects.
Why classic MCP tool calling hits a context wall at enterprise scale
In What is an AI agent harness? we looked at how an agent loop feeds tool definitions and tool results back into the context window on every turn. Two published measurements show how fast classic MCP breaks down on large APIs:
- The definition footprint (Cloudflare, February 2026): exposing the full Cloudflare API as native MCP schemas requires
2,594tools consuming1,170,523tokens (measured withtiktoken), or585%of a 200,000-token context window before the user types a single word. Replacing those schemas with two Code Mode tools (searchover the pre-resolved OpenAPI spec andexecutein a sandboxed Worker) drops the footprint to1,069tokens, a99.9%input-token reduction. - The intermediate payload tax (Anthropic, November 2025): copying a meeting transcript from Google Drive into Salesforce via classic tool calls forces the model to read and rewrite the entire document across turns. Moving that loop into code execution cut token usage in Anthropic's example from
150,000tokens to2,000tokens, a98.7%saving.
Server-side Code Mode versus client-side REPL in Claude Code
Code Mode now appears in two distinct places across the stack, and across adjacent harnesses like Browser Use 1.0 (which deleted 90 percent of its old library in favor of a Python REPL over raw CDP), Unharnessed, and Prime Agent:
- Server-side sandboxes (Cloudflare Workers): generated JavaScript never receives API credentials, outbound
fetch()andconnect()are blocked by default, and connector calls cross the sandbox boundary strictly through Workers RPC. - Client-side harness REPL (Claude Code v2.1.323+): enabled via
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1, Claude Code exposesREPLandPollso the model writes JavaScript that chains file reads, shell commands, and MCP calls in one turn while variables persist in memory across turns (up to 10 minutes when waiting, or 2 hours in background mode). For teams running this inside corporate networks, see our companion guide on self-hosted Claude Managed Agents architecture and limits.
The hidden trade-off: scripts answer only what they were asked
Code Mode looks strictly superior until you compare both modes on real business records. When evaluating classic multi-round MCP calls against single-turn scripts on a five-case commercial lending server (40,914 characters handled across four classic rounds on a link-integrity check versus 3,417 characters once a script knew the tools), a crucial qualitative difference emerged:
- A script answers the exact question it was written for: when a JavaScript filter maps six fields out of each loan record, every other field stays invisible inside the REPL and never reaches the model.
- A model reading full records notices unasked anomalies: in the classic sessions, without being prompted, the model flagged reminders that were never sent, statuses sitting behind their due dates, and a closed review carrying an empty checklist.
- Code Mode shrinks transport, not semantic ambiguity: giving an agent a fast JavaScript loop over raw ERP endpoints still leaves it guessing whether
TRCODE = 8is a wholesale invoice or a return, which status code blocks shipment, and which write call triggers a statutory tax seal.
The strongest production architecture combines both layers: use Code Mode so multi-step loops do not drown the context window, and back every tool call with an enterprise business ontology that surfaces explicit anomaly flags, verified entity joins, and human-gated write actions.