MCPClient
MCPClient manages a single MCP server subprocess. It handles starting the process, initializing the MCP session via JSON-RPC, calling tools, and stopping the process with cleanup.
MCPClient instances are created internally by
MCPManager.create_client().
You should not instantiate them directly in most cases.
Properties
process
The underlying subprocess object. None before start() is called.
tools
List of tool definitions retrieved from the MCP server after initialization.
start
start() -> bool
Spawn the MCP server process, initialize the MCP session, and retrieve the list
of available tools. Returns True on success, False if initialization fails.
The process runs in a sandboxed environment according to the service’s
sandbox_config.
Returns
bool — True if the process started and initialized successfully.
stop
stop() -> None
Stop the MCP server process. Attempts a graceful JSON-RPC shutdown first, then
falls back to SIGTERM, and finally SIGKILL if needed. Cleans up the sandbox
directory after the process stops.
call_tool
call_tool(tool_name, arguments) -> dict[str, Any]
Call a tool on the MCP server and return the result.
Parameters
tool_name
Name of the tool to invoke.
arguments
Arguments to pass to the tool.
Returns
dict[str, Any] — The tool result from the MCP server.
call_method
call_method(method, params) -> Any
Send a JSON-RPC request to the MCP server and wait for the response. Raises
TimeoutError after 30 seconds if no response is received. Raises
RuntimeError if the client is shutting down.
Parameters
method
The JSON-RPC method name (e.g., "tools/call", "tools/list").
params
Parameters for the JSON-RPC request.
Returns
Any — The result field from the JSON-RPC response.
get_tools
get_tools() -> list[dict[str, Any]]
Return a copy of the tool definitions retrieved during initialization.
Returns
list[dict[str, Any]]