fastmcp.experimental.client.code_mode
Client-side CodeMode: discovery and sandboxed execution over remote tools.
CodeModeClient wraps a Client or ClientGroup and presents the same
discovery + execute meta-tools as the server-side CodeMode transform. The
sandbox runs locally; each call_tool inside it is an ordinary tools/call
on the wrapped client, so servers never see the generated code and need no
CodeMode support of their own.
This module is experimental and may change without deprecation.
Classes
CodeModeClient
Present a clientβs tools through CodeMode discovery and execute tools.
list_tools() returns only the meta-tools (by default search,
get_schema, and execute). call_tool() runs them locally: discovery
reads the wrapped clientβs live tool list, and execute runs Python in a
sandbox where call_tool(name, params) calls the wrapped client.
Wrapping a ClientGroup lets one execute block chain tools from several
servers, using the groupβs namespaced tool names.
Args:
client: The connected (or connectable)ClientorClientGroupwhose tools the meta-tools expose.sandbox_provider: Executes generated code. Defaults toMontySandboxProvider, which requiresfastmcp[code-mode].discovery_tools: Discovery tool factories, as forCodeMode. Defaults toSearchandGetSchemas.execute_tool_name: Name of the execute tool.execute_description: Description of the execute tool.max_tool_calls: Maximumcall_toolinvocations perexecute;Noneremoves the limit.
client
list_tools
call_tool_mcp
Client.call_tool_mcp, a failing tool produces a result with
is_error set rather than raising.
call_tool
Client.call_tool does.
Raises:
ToolError: If the tool fails andraise_on_erroris true.