Rust Implementation Structure
Relevant source files
The following files were used as context for generating this wiki page:
The container_use_mcp project is a Rust-based extension for the Zed editor designed to integrate the Model Context Protocol (MCP) server for containerized environments. It leverages the zed_extension_api to provide coding agents within Zed access to the cu (Container Use) binary, facilitating secure and isolated task execution.
The implementation is structured as a dynamic library (cdylib) that implements the zed::Extension trait. This allows Zed to load the extension and manage the lifecycle of the context server process, handling binary discovery, path caching, and configuration schema generation.
Sources: Cargo.toml:11-12, src/container_use_mcp.rs:69-71, README.md:3-5
Extension Architecture
The core of the implementation resides in the ContainerUseMcpExtension struct and its implementation of the zed::Extension trait. The architecture focuses on two primary responsibilities: locating the cu binary and configuring the execution environment for the MCP server.
Core Data Structures
| Structure | Purpose |
|---|---|
ContainerUseMcpExtension | Manages the extension's state, specifically the cached_binary_path. |
ContainerUseMcpSettings | Defines the deserialization schema for user-provided settings, such as cu_path. |
Command | A structure returned to Zed containing the binary path, arguments (stdio), and environment variables. |
Sources: src/container_use_mcp.rs:11-14, src/container_use_mcp.rs:16-18, src/container_use_mcp.rs:88-92
Binary Discovery Logic
The extension employs a multi-tiered approach to find the cu binary required to run the MCP server. It first checks for a user-configured path, then falls back to searching the system's PATH.
The logic for searching the system PATH utilizes the which command, which is explicitly declared as a required capability in the extension configuration.
Sources: src/container_use_mcp.rs:26-53, extension.toml:11-14
Component Interaction
The extension interacts with Zed through the zed_extension_api. The following sequence diagram illustrates how Zed initializes the context server command.
Configuration and Metadata
The extension provides metadata to Zed to facilitate user configuration and discovery. This is handled through the context_server_configuration method and external configuration files.
Configuration Schema
The extension uses schemars to generate a JSON schema from the ContainerUseMcpSettings Rust struct. This schema is passed to Zed to provide autocompletion and validation in the user's settings.json.
| Field | Type | Description |
|---|---|---|
cu_path | Option<String> | Optional path to the cu binary. If omitted, the extension searches the PATH. |
Sources: src/container_use_mcp.rs:11-14, src/container_use_mcp.rs:109-111
External Metadata
The extension is identified by the ID mcp-server-container-use and defines the MCP server under the name container-use-mcp.
[context_servers.container-use-mcp]
name = "Container Use MCP Server"
Sources: extension.toml:1-17
Implementation Details
Dependency Management
The project relies on specific versions of the Zed API and serialization libraries to ensure compatibility.
[dependencies]
serde = "1.0"
schemars = "0.8"
zed_extension_api = "0.5.0"
Sources: Cargo.toml:14-17
Extension Initialization
The extension is registered using the zed::register_extension! macro, which exports the necessary symbols for Zed to load the library. The new function initializes the extension state with no cached binary path.
Sources: src/container_use_mcp.rs:72-76, src/container_use_mcp.rs:120
Resource Integration
The extension embeds external documentation and settings into the binary using the include_str! macro. These are used to provide the user with installation instructions and default configuration values within the Zed UI.
Sources: src/container_use_mcp.rs:106-108, configuration/installation_instructions.md:1
Summary
The Rust implementation of the container_use_mcp extension provides a robust bridge between the Zed editor and the Container Use MCP server. By implementing the zed::Extension trait, it automates the discovery of the cu binary and manages context server configurations, ensuring that coding agents can operate within isolated containerized environments as defined by project .rules.
Sources: src/container_use_mcp.rs:69-119, README.md:21-25