Architecture Deep Dive

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

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.

Updated: By Eterna Engineering (MCP Infrastructure & Execution Team)Read as Markdown
Direct answer: Why does execute_code outperform per-endpoint MCP tools for trading?

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.

Top-Level Tools3 vs 30-80+Minimal prompt schema footprint
Round-Trips / Trade1 vs 6-10Check, compute, size, execute atomically
Token Reduction~90% fewerIntermediate JSON stays inside Deno
Math AccuracyDeterministic JSNo LLM floating-point sizing errors
https://mcp.eterna.exchange/mcp

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-by-step execution comparison for one risk-sized perpetual trade
StepPer-Endpoint MCP ServerEterna execute_code MCP
0. Tool schema preload30 to 80 tool JSON schemas injected every turn3 tool schemas (search_sdk, search_examples, execute_code)
1. Check balanceTurn 1: get_balance -> full wallet JSON into contextInside same TypeScript script (Promise.all)
2. Check open positionsTurn 2: get_positions -> full array into contextInside same TypeScript script
3. Fetch ticker & RSITurns 3-4: get_ticker + get_klines (100+ candles into context)Inside same script (eterna.getTickers + eterna.getRsi)
4. Fetch lot-size rulesTurn 5: get_instruments -> huge JSON spec into contextInside same script (eterna.getInstruments)
5. Compute qty & stopLLM does mental arithmetic (prone to step-size bugs)Exact Math.floor(rawQty / step) * step in Deno
6. Set leverage & place orderTurns 6-7: set_leverage + place_order (stale price risk)Executed milliseconds after ticker read in same worker
Total LLM round-trips7 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.

FAQ

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%.
Primary Sources

References & verification links

Start Trading via MCP

Connect your AI agent in 30 seconds

One remote MCP URL. 800+ USDT perpetuals, 380+ spot pairs, 0.014% maker / 0.035% taker, no KYC.

View on GitHub