Standard JSON tool calling hits a hard wall when you connect agents to real enterprise infrastructure. Nicola Mastromarino, writing on DEV.to, argues that while the native function calling pattern works for toy apps with three tools, it collapses under the weight of production scale. The culprit is the 'Upfront Context Tax': exposing the full Cloudflare API via Model Context Protocol (MCP) consumes roughly 1.17 million tokens just to load schema definitions, even before the user types a single prompt.

The 80,000 Token Pre-Flight Burn

When an agent is connected to four MCP servers with 150+ endpoints, the system prompt becomes a graveyard of JSON schemas. Mastromarino notes that simply loading tool definitions can burn 80,000 tokens. Worse, attention degrades as context grows. When an LLM has to choose between 200 similarly named tools, hallucinated parameters and wrong tool selections spike. The model isn't reasoning; it's drowning in metadata.

Death by Sequential Round-Trips

The latency issue is even more critical than the token count. Consider a workflow to 'find failed deployments and open tickets.' In standard JSON mode, this requires a chain of sequential calls: list deployments, then fetch logs for each one, then create tickets. Each step forces a network round-trip and re-ingests the entire conversation history. Mastromarino describes this as 'death by 10 sequential round-trips,' where users stare at a spinner for 45 seconds while the LLM pays for full-context prefill on every hop.

Sandboxed Code Execution Fixes the Math

The solution is Code Mode, a pattern popularized by Cloudflare Agents, FastMCP, and the Vercel AI SDK. Instead of dumping schemas into the prompt, you expose a typed SDK inside a sandbox and give the model just two meta-tools: search_spec and execute_code. This reduces the context overhead to around 1,000 tokens. The agent writes a single script to loop, filter, and aggregate data inside the execution environment, returning only the final outcome. One LLM generation replaces 12 JSON round-trips.

The Red Team View on Security and Failures

Code Mode isn't a silver bullet. Mastromarino warns that executing LLM-generated code introduces a different class of production failures. You need strict isolationβ€”V8 isolates, QuickJS WebAssembly sandboxes, or MicroVMsβ€”because exec() on a host container is an incident waiting to happen. Additionally, if a step in a generated script throws an unhandled exception, you lose the granular step-by-step visibility found in standard agent graphs like LangGraph. Your sandbox must return structured tracebacks to allow for self-healing without re-running non-idempotent mutations.

Key Takeaways

  • Use Direct Tool Calling for < 15 tools with small schemas.
  • Use Code Mode for workflows involving loops, data filtering, or parallel requests.
  • Never run LLM-generated code without strict sandbox isolation.
  • Schema bloat can consume 1.17M tokens for large APIs; Code Mode reduces this to ~1,000.

The Bottom Line

LLMs are better at writing code than chaining JSON. If you're still forcing agents to orchestrate logic through conversation history, you're asking the attention mechanism to act as a CPU and RAM simultaneously. Offload control flow to a deterministic runtime.