Overview

Code Mode is useful when you connect many MCP servers and do not want every model request to include every tool definition. Instead of exposing each tool directly, ModRouter exposes a compact set of meta-tools that let the model discover tool definitions and execute tool orchestration code in a sandbox. Use Code Mode when:
  • You have several MCP servers connected.
  • Workflows require multiple tool calls.
  • Tool definitions take too much context.
  • Intermediate tool results do not all need to be sent back to the model.
For simple one-tool or two-tool use cases, classic MCP tool calling is usually easier.

How It Works

Code Mode exposes meta-tools such as: The model reads only the tool definitions it needs, writes orchestration code, and receives a compact result.

Enable Code Mode

Enable Code Mode per MCP client:

Send a Request

Go SDK

Practical Guidance

Enable Code Mode for broad tool surfaces such as search, documents, CRM, databases, and internal APIs. Keep small utility servers in classic MCP mode when direct tool calling is clearer.