Code Mode for MCP: 98% Fewer Tokens, 15x Faster Execution
What is Code Mode?
Code Mode for MCP: 98% Fewer Tokens, 15x Faster Execution
What is Code Mode?
Code Mode is a paradigm shift in how LLMs interact with tools. Instead of sequential tool-calling, the LLM writes and executes code that orchestrates multiple operations in a single pass. The results are dramatic: ~200 tokens instead of 50,000. One execution instead of dozens of round trips.

Code-Mode token reduction
Implementations from Cloudflare and Anthropic proved the concept works. They showed impressive efficiency gains — constant token overhead regardless of server count, complex workflows in single executions instead of countless round trips.
But those solutions require sending your code and credentials to external servers and using vendor models. Your business logic leaves your infrastructure. Your MCP tokens pass through third-party systems. There’s been a gap in the ecosystem for developers who want Code Mode’s benefits while maintaining complete control over their execution environment.
Building on Open Standards
My startup has been working on pctx — exploring what Code Mode looks like when built on open principles:
Core principles:
- Open Source: MIT licensed, audit the code yourself
- Local-First: Your data never leaves your infrastructure
- Zero Dependencies: Single binary, no runtime required
- Built in Rust: Memory-safe, performant, reliable
The Architecture
// Two isolated Deno sandboxes
let compiler = DenoSandbox::new(CompilerOnly);
let executor = DenoSandbox::new(MCPAccessOnly);
Everything runs in locked-down sandboxes:
- No filesystem access
- No network access except your configured MCP servers
- Memory and CPU limits enforced
- TypeScript validation catches errors before execution
Quick Start
# Single binary install
curl -fsSL https://pctx.sh/install | sh
# Or with npm
npm i -g @portofcontext/pctx
# Or with brew
brew install portofcontext/tap/pctx
# Configure your MCP servers locally
pctx init
pctx add stripe https://mcp.stripe.com --bearer '${env:STRIPE_KEY}'
pctx add github https://mcp.github.com --token '${env:GITHUB_TOKEN}'
# Run locally with terminal ui for observing traffic
pctx dev
The TUI shows everything happening in real-time — connected servers, generated code, execution traces. No black box.

Real Performance Gains
Production metrics from a customer onboarding workflow:
- Token usage: 98.6% reduction
- Execution time: 16x faster
- Success rate: 72% → 94%
Code Mode in Practice
Instead of this:
LLM calls stripe.getCustomer()
LLM processes response (x hundred tokens)
LLM calls hubspot.findDeal()
LLM processes response (x thousand tokens)
LLM calls slack.postMessage()
LLM processes response (x hundred tokens)
The LLM writes this:
const customer = await stripe.getCustomer(id);
const deal = await hubspot.findDeal(customer.email);
await slack.postMessage(`New deal for ${customer.name}`);
# LLM processes ~5 tokens
One pass. Minimal tokens. Full control.
Beyond Tool Calling
Code Mode enables patterns that are impossible with traditional tool-calling:
Parallel operations:
const results = await Promise.all([
stripe.listCharges(),
github.listPRs(),
slack.getChannels()
]);
Complex error handling:
try {
return await primary.getData();
} catch (e) {
return await fallback.getData();
}
Conditional logic:
if (customer.subscription === 'enterprise') {
await slack.notifySales(customer);
}
What’s Next
- Native SDKs for code-mode in Python and TypeScript
- More MCP server adapters
- Community-contributed patterns
Join the development on GitHub or try the cloud version at portofcontext.com
메타데이터
- post_id
- a0f1f31662cb
- slug
- code-mode-for-mcp-98-fewer-tokens-15x-faster-execution-a0f1f31662cb
- url
- https://medium.com/@patkelly_72780/code-mode-for-mcp-98-fewer-tokens-15x-faster-execution-a0f1f31662cb
- canonical_url
- https://medium.com/@patkelly_72780/code-mode-for-mcp-98-fewer-tokens-15x-faster-execution-a0f1f31662cb
- author_url
- https://medium.com/@patkelly_72780
- status
- ok
- fetched_at
- 2026-08-04 00:16:55