codeMode property
Whether to enable code mode for this MCP server.
When true, generates search and execute tools that allow LLMs
to discover and orchestrate multiple tool calls in a single JavaScript
program instead of making sequential round-trips. This reduces latency
(N round-trips → 1), reduces token usage, enables parallelism via
Promise.all, and allows complex logic (math, data transformations).
The search tool lets LLMs discover available tools by name or
description without loading all tool schemas into context. It returns
matching tools at brief, detailed, or full detail levels.
The execute tool spawns a sandboxed Node.js subprocess where all
code-mode-enabled tools are available as external_* async functions
and via the generic call_tool(name, params) function. The LLM
generates JavaScript code that calls these functions and returns a
structured result.
Tools can be individually excluded from code mode by setting
@Tool(codeMode: false), which removes them from the search
index and the sandbox environment.
Code mode requires Node.js to be installed on the system.
Example:
@Server(transport: McpTransport.http, codeMode: true)
class UserService {
@Tool(description: 'Create user')
Future<User> createUser() async { ... }
}
Defaults to false.
Implementation
final bool codeMode;