Principle:AI Shell Team Aish MCP Manager Initialization
| Knowledge Sources | |
|---|---|
| Domains | MCP, Configuration |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Pattern for initializing a server lifecycle manager that owns per-server state entries without performing any I/O, deferring connection to explicit start calls.
Description
MCP Manager Initialization is the mechanism that builds a manager object from resolved MCP settings. The constructor creates a ServerState entry for each configured server (including disabled ones, so the UI can list them before connection). Each entry carries the server's initial status (enabled or disabled based on configuration). No I/O is performed during construction — the manager is ready to connect but has not contacted any server.
The manager uses a generation counter to invalidate stale drivers during reconfiguration, a shutdown watch channel to signal all drivers to stop, and a self-referential weak handle so `&self` methods can spawn drivers without storing a strong `Arc<Self>` reference.
This pattern solves the problem of decoupling configuration from connection: the manager can be built from any configuration state, and connections are started explicitly when the runtime is ready.
Usage
Use this principle when initializing a server lifecycle manager that must support deferred connection, hot-reload, and clean shutdown. The constructor should be side-effect-free; the start method should trigger I/O.
Theoretical Basis
The initialization is a side-effect-free constructor with deferred I/O:
# Abstract algorithm (NOT real implementation)
def new(settings):
servers = [ServerState(name, initial_status(settings, s)) for s in settings.servers]
shutdown_tx, shutdown_rx = watch_channel(initial=False)
return Manager(
settings=settings,
servers=servers,
generation=0,
shutdown_tx=shutdown_tx,
shutdown_rx=shutdown_rx,
)
# No I/O performed — call start() to connect
Key design ideas:
- Disabled entries preserved: disabled servers get entries so the UI can display them
- Generation counter: incremented on shutdown/reload to invalidate stale drivers
- Weak self-reference: allows `&self` methods to spawn drivers without `Arc<Self>` field