Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

1.9 KB
Raw Blame

Code Mode

CodeMode collapses an entire tool catalog into three meta-tools: search (keyword-based discovery), get_schema (parameter details), and execute (run Python scripts that chain tool calls in a sandbox). Instead of burning context tokens on every intermediate result, the LLM writes a script that runs server-side and returns only the final answer.

Run

uv run python server.py   # in one terminal
uv run python client.py   # in another

Example Output

══════════════════ CodeMode Transform ══════════════════

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ list_tools() ──────────────┐
β”‚ Tool       Description                   β”‚
β”‚ search     Search for available tools    β”‚
β”‚ get_schema Get parameter schemas         β”‚
β”‚ execute    Chain `await call_tool(...)`  β”‚
└── 8 backend tools collapsed into 3 β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€ search(query="math arithmetic") ─────┐
β”‚ #   Tool      Description                β”‚
β”‚ 1   add       Add two numbers together.  β”‚
β”‚ 2   multiply  Multiply two numbers.      β”‚
β”‚ 3   fibonacci Generate the first n ...   β”‚
└── 3 results β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ execute ───────────────────┐
β”‚ a = await call_tool("add", {"a": 3 ...  β”‚
β”‚ b = await call_tool("multiply", ...     β”‚
β”‚ return b                                 β”‚
└── result: 14.0 β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The key insight: with standard MCP, each call_tool is a round-trip through the LLM. With CodeMode, the LLM writes one script and all the tool calls happen server-side. Intermediate data never touches the context window.