# MCP execute_code vs Tool Calling: Why Code-Execution MCP Uses ~90% Fewer Tokens

> Traditional crypto MCP servers register 30 to 80 individual tool schemas, forcing 6 to 10 sequential LLM turns and dumping huge JSON market payloads into context for one trade. Eterna's execute_code architecture exposes only 3 MCP tools (search_sdk, search_examples, execute_code) and runs typed TypeScript inside a Deno sandbox, cutting token usage by roughly 90% and executing multi-step trade logic atomically.

- Canonical URL: https://ai.eterna.exchange/guides/execute-code-vs-tool-calling
- Last updated: November 23, 2026
- Author: Eterna Engineering (MCP Infrastructure & Execution Team)
- MCP endpoint: https://mcp.eterna.exchange/mcp

In live financial markets, extra LLM round-trips do not just waste API tokens: they introduce price slippage between reading a ticker and placing a stop-loss. Here is the architectural breakdown behind Eterna's Deno sandbox model.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| Top-Level Tools | 3 vs 30-80+ | Minimal prompt schema footprint |
| Round-Trips / Trade | 1 vs 6-10 | Check, compute, size, execute atomically |
| Token Reduction | ~90% fewer | Intermediate JSON stays inside Deno |
| Math Accuracy | Deterministic JS | No LLM floating-point sizing errors |

## Anatomy of a single risk-sized trade: 8 tool calls vs 1 execute_code call

Compare what happens on the wire when a user asks: 'If BTC 1h RSI is under 35 and I have no open position, open a 5x long risking 1% of equity with a 2% stop.'

| Step | Per-Endpoint MCP Server | Eterna execute_code MCP |
| --- | --- | --- |
| 0. Tool schema preload | 30 to 80 tool JSON schemas injected every turn | 3 tool schemas (search_sdk, search_examples, execute_code) |
| 1. Check balance | Turn 1: get_balance -> full wallet JSON into context | Inside same TypeScript script (Promise.all) |
| 2. Check open positions | Turn 2: get_positions -> full array into context | Inside same TypeScript script |
| 3. Fetch ticker & RSI | Turns 3-4: get_ticker + get_klines (100+ candles into context) | Inside same script (eterna.getTickers + eterna.getRsi) |
| 4. Fetch lot-size rules | Turn 5: get_instruments -> huge JSON spec into context | Inside same script (eterna.getInstruments) |
| 5. Compute qty & stop | LLM does mental arithmetic (prone to step-size bugs) | Exact Math.floor(rawQty / step) * step in Deno |
| 6. Set leverage & place order | Turns 6-7: set_leverage + place_order (stale price risk) | Executed milliseconds after ticker read in same worker |
| Total LLM round-trips | 7 to 8 sequential turns (15-40 seconds) | 1 execute_code call (<2 seconds total execution) |

## Four production advantages beyond token savings

- Eliminates LLM floating-point errors: exchange matching engines reject orders that violate qtyStep or tickSize. TypeScript computes exact floored values directly from eterna.getInstruments.
- Eliminates stale-price slippage: in volatile crypto markets, 25 seconds of multi-turn tool chatter moves BTC 0.3% to 1%. Running ticker read, sizing, and placeOrder inside Deno executes in milliseconds.
- Parallel multi-asset scanning: Promise.all inside execute_code scans 15 symbols in parallel and returns only the top 3 matches, keeping context crisp.
- Inspectable audit trail: every human-in-the-loop approval prompt displays one clean TypeScript script instead of 8 disjointed JSON tool calls.

## Progressive disclosure with search_sdk and search_examples

A common question about code-execution MCP is: how does the LLM know the exact SDK methods if they are not listed as 30 separate MCP tools? Eterna solves this with progressive disclosure through search_sdk (supporting list, summary, full, params, and keywords detail levels) and semantic search_examples.

The model fetches only the exact signatures it needs for the current task, keeping base system context lean while guaranteeing zero invented parameters.

## Frequently Asked Questions

### Is executing LLM-generated TypeScript inside execute_code secure?

Yes. Every execute_code invocation runs inside an ephemeral, isolated Deno worker with no filesystem access, no arbitrary outbound network access, and strictly scoped pre-authenticated eterna.* bindings tied to your OAuth sub-account.

### How much does execute_code save in LLM token costs?

On typical multi-step trading and market-scanning workflows, running one execute_code script instead of chaining 6 to 10 individual MCP tools reduces total prompt and completion token volume by roughly 90%.

## References & Primary Sources

- [Anthropic Engineering: Code Execution with MCP](https://www.anthropic.com/engineering/code-execution-with-mcp): Industry architecture reference validating progressive discovery and sandboxed code execution over massive MCP tool sets.
- [Eterna MCP Server Card](https://ai.eterna.exchange/.well-known/mcp/server-card.json): Declares Eterna's 3-tool surface: execute_code, search_sdk, search_examples.

## Related Guides

- [Best MCP Server for Crypto Trading: Architecture, Fees, and Setup](https://ai.eterna.exchange/mcp-crypto-trading)
- [Eterna MCP SDK Reference: All 30+ eterna.* Methods](https://ai.eterna.exchange/sdk)
- [How to Build an AI Crypto Trading Agent with MCP (Step-by-Step)](https://ai.eterna.exchange/ai-trading-agent)
- [Eterna MCP vs Self-Hosted CCXT & Custom MCP Servers](https://ai.eterna.exchange/compare/eterna-vs-ccxt)
