MCPService, MCPClient & MCPManager

View as MarkdownOpen in Claude

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.

1from signalwire.mcp_gateway import MCPService, MCPClient, MCPManager

MCPService

A dataclass that holds the configuration for a single MCP service. Loaded automatically from the gateway configuration file by MCPManager.

Properties

name
str

Unique name identifying this MCP service.

command
list[str]

The command and arguments used to spawn the MCP server process (e.g., ["python3", "my_server.py"]).

description
str

Human-readable description of what this service provides.

enabled
boolDefaults to True

Whether this service is enabled. Disabled services are skipped during loading.

sandbox_config
dict[str, Any]

Sandbox configuration controlling process isolation. Defaults to:

1{"enabled": True, "resource_limits": True, "restricted_env": True}
sandbox_config.enabled
boolDefaults to True

Enable process sandboxing. When False, the MCP server runs with full environment access.

sandbox_config.resource_limits
boolDefaults to True

Apply CPU, memory, process count, and file size limits to the spawned process.

sandbox_config.restricted_env
boolDefaults to True

Run with a minimal environment (PATH, HOME, TMPDIR only). When False, the full parent environment is inherited.

sandbox_config.drop_privileges
boolDefaults to False

Drop to the nobody user when running as root.

sandbox_config.working_dir
str

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
dict[str, MCPService]

Dictionary mapping service names to their MCPService definitions.

Methods

For the MCPClient class (created by create_client()), see the MCPClient reference.