Extension Lifecycle
Relevant source files
The following files were used as context for generating this wiki page:
The Extension Lifecycle for the Container Use MCP Server defines how the Zed editor initializes, configures, and executes the extension to provide containerized environments for coding agents. This process involves registering the extension within the Zed ecosystem, resolving dependencies (specifically the cu binary), and establishing a communication channel via the Model Context Protocol (MCP).
The lifecycle is managed through the zed_extension_api, which provides hooks for instantiation, configuration retrieval, and command execution. The primary objective is to ensure that the cu (Container Use) binary is correctly located—either via user settings or the system PATH—and then executed as a child process using the stdio communication protocol.
Sources: src/container_use_mcp.rs:1-13, extension.toml:1-10, README.md:1-5
Registration and Initialization
The extension is registered using the zed::register_extension! macro, which exports the necessary symbols for Zed to load the library as a cdylib. Upon loading, Zed invokes the new() method to create an instance of the ContainerUseMcpExtension struct.
Initialization Components
The extension state is minimal during the initial load, primarily focusing on caching the resolved path to the external tool.
| Component | Description |
|---|---|
ContainerUseMcpExtension | The main state struct holding the cached_binary_path. |
zed::register_extension! | Macro that registers the extension with the Zed host. |
new() | Initializes the extension state with no cached path. |
Sources: src/container_use_mcp.rs:16-18, src/container_use_mcp.rs:51-55, src/container_use_mcp.rs:90, Cargo.toml:11-13
The diagram above shows the initial boot sequence of the extension within the Zed editor process.
Sources: src/container_use_mcp.rs:51-55, Cargo.toml:11-13
Configuration and Capability Resolution
Before running the MCP server, the extension provides Zed with metadata regarding its requirements and settings. This is handled through context_server_configuration and the extension.toml manifest.
Metadata and Capabilities
The extension.toml file defines the extension's identity and its required system capabilities, such as the ability to execute the which command to locate binaries.
- ID:
mcp-server-container-use - Capabilities:
process:execfor thewhichcommand. - Context Server Name:
ContainerUseMcpServer
Sources: extension.toml:1-14
Settings Schema
The extension defines a ContainerUseMcpSettings struct which is converted into a JSON schema for Zed's settings UI. This allows users to manually specify the cu_path if the binary is not in the system's standard execution path.
Sources: src/container_use_mcp.rs:10-14, src/container_use_mcp.rs:80-82
Binary Path Resolution Logic
The extension employs a multi-step strategy to locate the cu binary required to run the MCP server. This logic is encapsulated within context_server_binary_path.
- Cache Check: It first checks if a path is already cached in the extension state and verifies it exists on the filesystem.
- System PATH Search: If no valid cached path exists, it executes the
which cucommand (as permitted by its capabilities) to find the binary in the user's environment. - Error Handling: If the binary cannot be found, it returns an error directing the user to the installation instructions.
Sources: src/container_use_mcp.rs:20-47, extension.toml:11-14
The flowchart illustrates the priority-based logic used to resolve the location of the Container Use executable.
Sources: src/container_use_mcp.rs:24-46
Server Execution Lifecycle
The core of the lifecycle is the context_server_command method. This method is called by Zed when it needs to start the MCP server for a specific project.
Process Start Sequence
- Settings Retrieval: The extension fetches project-specific settings for
container-use-mcp. - User Override: If
cu_pathis provided in settings, it updates thecached_binary_path. - Command Construction: It constructs a
zed_extension_api::Commandusing the resolved binary path. - Stdio Communication: The command is configured to use
stdioas the communication argument, enabling the MCP protocol.
Sources: src/container_use_mcp.rs:57-75, README.md:15-25
Execution Details
| Parameter | Value / Source |
|---|---|
| Command | Resolved path to cu binary |
| Arguments | ["stdio"] |
| Environment | Empty (Inherited or Default) |
Sources: src/container_use_mcp.rs:71-75
This sequence diagram shows the interaction between the Zed host and the extension to prepare the execution command.
Sources: src/container_use_mcp.rs:20-47, src/container_use_mcp.rs:57-76
Summary of Lifecycle Events
The lifecycle ensures that the MCP server is available for coding agents to utilize containerized environments. By integrating with Zed's settings and process execution API, the extension provides a flexible way to manage the cu tool.
- Registration:
register_extension!makes the extension known to Zed. - Configuration:
context_server_configurationprovides the necessary UI and installation guidance. - Path Resolution: The extension determines where the
cubinary resides. - Execution:
context_server_commandlaunches the MCP server to begin providing containerized services.
Sources: src/container_use_mcp.rs:51-89, extension.toml:1-17, README.md:7-13