MCPService, MCPClient & MCPManager
MCPService, MCPClient & MCPManager
These classes handle the low-level lifecycle of MCP server processes: defining service configurations, spawning sandboxed subprocesses, communicating over JSON-RPC, and managing multiple services.
MCPService
A dataclass that holds the configuration for a single MCP service. Loaded
automatically from the gateway configuration file by
MCPManager.
Properties
name
Unique name identifying this MCP service.
command
The command and arguments used to spawn the MCP server process (e.g.,
["python3", "my_server.py"]).
description
Human-readable description of what this service provides.
enabled
Whether this service is enabled. Disabled services are skipped during loading.
sandbox_config
Sandbox configuration controlling process isolation. Defaults to:
sandbox_config.enabled
Enable process sandboxing. When False, the MCP server runs with full
environment access.
sandbox_config.resource_limits
Apply CPU, memory, process count, and file size limits to the spawned process.
sandbox_config.restricted_env
Run with a minimal environment (PATH, HOME, TMPDIR only). When False, the
full parent environment is inherited.
sandbox_config.drop_privileges
Drop to the nobody user when running as root.
sandbox_config.working_dir
Working directory for the spawned process. Defaults to the current directory.
MCPManager
Manages multiple MCP services and their client lifecycles. Loads service definitions from the gateway configuration, creates clients on demand, and handles bulk shutdown.
Properties
services
Dictionary mapping service names to their MCPService definitions.
Methods
Create and start a new MCP client for a service.
Discover a service’s available tools.
Validate that all configured services can start.
Stop all active MCP clients.
For the MCPClient class (created by create_client()), see the
MCPClient reference.