MCP's Context Tax: Code Mode and Progressive Gateways
Eager MCP tool schemas bloat prompts and hurt tool routing. See how Claude Code Mode and progressive disclosure gateways fix the context tax.

For the past few weeks, one architectural inconsistency has been bugging me. When we build Agent Skills, we lazy-load them with a one-liner description in context and only pull the full playbook when a task actually matches. Yet with the Model Context Protocol (MCP) and preloaded toolchains, most teams still dump every full JSON schema into the system prompt on turn zero and keep it pinned there for the entire session.
If lazy loading works so well for Skills, why are we not applying the same discipline to every tool, server, and instruction?
Solving this at enterprise scale requires replacing flat, eager tool registration with progressive disclosure gateways, dynamic tool routing, and server-side execution pipelines.
Why Does Eager MCP Schema Loading Break at Scale?
Standard MCP clients treat the model’s context window as an unbounded service registry. When an agent connects to five or six enterprise MCP servers (GitHub, Jira, Postgres, Slack, observability, and internal deploy tools), the client calls tools/list on each server and dumps every full JSON schema into the system prompt on turn zero.
In production agent loops, this creates three compounding failure modes:
- Upfront Prompt Bloat: An enterprise MCP server often exposes dozens of tools, each carrying verbose descriptions, nested parameter objects, enum lists, and validation constraints. Across a multi-server setup, raw schema definitions consume a massive share of the context window on every single turn, even when a task only needs to read one file.
- Attention Dilution and Routing Drift: Transformer attention is not uniform across long contexts. Flooding the prompt prefix with overlapping tool definitions increases semantic collision between similar operations (such as
github_search_issues,jira_search_issues, andlinear_search_tickets), forcing the model to burn reasoning capacity disambiguating tools it will never invoke. - Intermediate Payload Ping-Pong: In traditional JSON tool-calling loops, every intermediate output passes back through the model’s context window to trigger the next step. Fetching a large log dump or database table just to extract five rows forces the model to ingest and re-process the entire payload twice.
How Anthropic and Cloudflare Proved the Shift
Over the past year, both Anthropic and Cloudflare converged on the same conclusion: loading every tool schema upfront and passing every intermediate result through the model’s context window does not scale.
- November 2025 (Anthropic): Anthropic outlined “code execution with MCP,” citing an example workflow where loading tools as code instead of eager definitions cut token usage from 150,000 tokens down to 2,000 tokens.
- February 2026 (Cloudflare Server-Side Code Mode): Cloudflare shipped Code Mode for its MCP server, wrapping over 2,500 Cloudflare API endpoints behind just two tools (
search()andexecute()). According to Cloudflare’s engineering write-up, an equivalent native MCP server would require 1.17 million tokens of schemas, whereas their two-tool server stays around 1,000 tokens (a 99.9% input-token reduction) and runs the model’s JavaScript inside a sandboxed Dynamic Worker isolate. - Late 2026 (Anthropic’s Experimental Code Mode,
v2.1.323+): Anthropic brought client-side Code Mode (CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1) into Claude Code. Anthropic has not published official token-saving benchmarks for the feature yet.
Time will tell if we get to really see these promised gains in day-to-day production workloads, especially once code-generation overhead and multi-step debugging retries are factored in.
What Is Claude Code Mode and How Does It Work?
Claude Code Mode is an experimental feature in Anthropic’s Claude Code (v2.1.323+, enabled via CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1) that lets the model write and run a single JavaScript block to chain multiple tool calls instead of sending one JSON tool request at a time.
In standard tool calling, every file search, edit, and test run requires a separate round-trip through the model’s context window. With Claude Code Mode, the model generates one short script that runs parallel reads, applies edits, filters noisy test stdout, and returns only the distilled result. For developers testing it locally, pressing Ctrl+O in the terminal expands the collapsed Code row so you can inspect the exact JavaScript the model executed.
Claude Code Mode Limitations vs. an Enterprise MCP Gateway
For engineering leaders, Staff architects, and CTOs, the distinction between client-side Code Mode and infrastructure-level gateways comes down to cost predictability, provider portability, and compliance. Per Anthropic’s Code Mode documentation, the experimental feature only runs in interactive terminal sessions on first-party Anthropic accounts. It is unavailable through gateways, Amazon Bedrock, Google Cloud Vertex/Agent Platform, Microsoft Foundry, the VS Code panel, the Desktop app, headless CI, or organizations enforcing HIPAA or Zero Data Retention (ZDR) policies.
Moving discovery and execution into a server-side MCP Gateway, the pattern pioneered by Cloudflare, gives organizations fixed-footprint tool discovery across any model provider, with centralized RBAC, sandboxing, and audit trails. For teams building internal MCP servers today, one immediate rule of thumb applies: keep tool descriptions concise and separate read-only discovery from execution so you do not lock your context budget to one client runtime.
Architecture: The Progressive Disclosure MCP Gateway
Instead of pushing context management onto every individual client or relying on provider-locked runtime flags, platform teams should enforce context hygiene at the MCP Gateway layer.
Eager Injection vs. Progressive Disclosure Topology
| Architectural Dimension | Standard Eager MCP Client | Progressive Disclosure MCP Gateway |
|---|---|---|
| Turn-Zero Context Footprint | Full JSON schemas for all connected servers | Lightweight capability index + 2 meta-tools (fixed footprint) |
| Schema Resolution | Static, upfront at session initialization | Lazy, just-in-time via semantic or lexical lookup |
| Execution Topology | Sequential JSON round-trips through model context | Batched gateway execution or scoped sub-agent isolation |
| Governance & Policy Enforcement | Client-side allowlists; brittle across IDEs and CLIs | Centralized RBAC, audit logging, and parameter validation |
| Provider Portability | Degrades sharply on smaller or cheaper routing models | Model-agnostic; works across Bedrock, Vertex, and local SLMs |
Three Core Gateway Primitives
A production progressive disclosure gateway sits between your agent runtimes (Claude Code, Cursor, or custom ADK and Temporal workers) and your downstream MCP servers, exposing a minimal, constant-size control surface:
- Tiered Tool Discovery (
gateway.discover_tools): Rather than exposing 200 raw tools, the gateway exposes a single discovery primitive supporting progressive detail levels (names_only,summary,full_schema). The agent queries by intent (for example,"query production postgres read replica"), and the gateway returns only the top 3 matching tool signatures. - Just-in-Time Schema Hydration (
gateway.hydrate_schema): Full JSON parameter schemas enter the active session state only after the agent selects a candidate tool, and can be evicted from the sliding context window once the sub-task completes. - Server-Side Pipeline Composition (
gateway.execute_pipeline): For multi-step data transformations (such as querying an observability store, filtering anomalies, and posting a summary), the gateway accepts a declarative step graph or constrained sandbox expression, executing intermediate joins server-side so raw payloads never pollute the LLM context window.
Reference: Minimal Progressive Disclosure Gateway Interface (TypeScript)
export interface DiscoveryRequest {
intent: string;
domain?: 'scm' | 'observability' | 'database' | 'ticketing';
detailLevel: 'summary' | 'full_schema';
limit?: number;
}
export interface HydratedTool {
qualifiedName: string; // e.g., "postgres_ro.execute_readonly_query"
summary: string;
inputSchema?: Record<string, unknown>; // Populated only when detailLevel === 'full_schema'
policyTier: 'auto_approve' | 'requires_approval';
}
export interface GatewayControlPlane {
discoverTools(req: DiscoveryRequest): Promise<HydratedTool[]>;
invokeTool<TInput, TOutput>(
qualifiedName: string,
args: TInput,
sessionContext: { traceId: string; role: string }
): Promise<TOutput>;
}
Mirroring Agent Skills at the Protocol Layer
As I explored in The Dead Files Wake Up, Agent Skills (SKILL.md manifests with progressive resource loading) outperform monolithic system prompts because they separate index metadata from execution payload. An agent only needs a 15-token trigger description to know a capability exists; it does not need the 2,000-token operational manual until the moment of invocation.
Treating MCP servers as lazily hydrated capability trees rather than eager prompt attachments applies that exact discipline to external tool ecosystems:
- Keep the root prompt under 2,000 tool tokens: Cap turn-zero registrations to core local primitives plus a single gateway discovery interface.
- Route discovery through deterministic indexes: Combine BM25 keyword matching with lightweight embedding search over curated tool tags rather than relying on an LLM to scan massive JSON arrays.
- Enforce policy boundaries at the gateway: When dynamic routing or programmatic chaining is enabled, static client-side regex hooks are no longer enough. Centralize RBAC, path and query validation, and audit telemetry inside the gateway proxy so every resolved tool call is verified before hitting downstream systems.
Summary Checklist for Platform Teams
- Audit your baseline token tax: Measure the exact token count injected into
systemandtoolsbefore turn one across your team’s standard IDE and CLI setups. - Eliminate eager server fan-out: Replace direct multi-server client connections with a unified MCP gateway that exposes lazy discovery (
discover_tools) and just-in-time schema hydration. - Isolate high-volume intermediate payloads: Push log filtering, AST parsing, and large JSON transformations into server-side gateway pipelines or isolated sub-agents so raw data stays out of your primary reasoning context.
