Understanding Model Context Protocol (MCP)
Relevant source files
The following files were used as context for generating this wiki page:
The Model Context Protocol (MCP) integration in this project facilitates a connection between the Zed editor and the container-use server. This architecture allows coding agents within the editor to operate within isolated, containerized environments, enhancing security and reproducibility for automated coding tasks.
The implementation acts as a bridge, managing the lifecycle of the MCP server process, handling configuration settings, and ensuring that the necessary cu binary is available on the host system to execute containerized commands.
Sources: extension.toml:1-5, README.md:1-5
Extension Architecture
The extension is built using the Zed Extension API and is implemented as a Rust library targeting cdylib. It implements the zed::Extension trait to manage the container-use-mcp context server.
Key Components
| Component | Description |
|---|---|
ContainerUseMcpExtension | The main state holder for the extension, managing cached paths for the cu binary. |
ContainerUseMcpSettings | Data structure for deserializing user-defined settings, specifically custom binary paths. |
cu binary | The external CLI tool that provides the actual containerized environment logic. |
Sources: src/container_use_mcp.rs:11-19, Cargo.toml:11-12
Process Initialization Flow
The following diagram illustrates how the extension locates the necessary binary and starts the MCP server.
The extension first checks for a user-provided path in settings before falling back to searching the system's PATH using the which command.
Sources: src/container_use_mcp.rs:24-52, extension.toml:10-12
Configuration and Settings
The extension supports dynamic configuration through Zed's settings mechanism. It defines a schema for settings and provides default instructions for users.
Settings Schema
Users can override the default behavior by providing a specific path to the cu binary in their global or project-specific settings.
{
"context_servers": {
"container-use-mcp": {
"settings": {
"cu_path": "/path/to/cu"
}
}
}
}
Sources: README.md:18-26, src/container_use_mcp.rs:11-14
Data Structures
The extension utilizes schemars to generate a JSON schema from Rust structs, ensuring type safety and editor integration for configuration.
#[derive(Debug, Deserialize, JsonSchema)]
struct ContainerUseMcpSettings {
/// Path to the cu binary (optional - will download if not provided)
cu_path: Option<String>,
}
Sources: src/container_use_mcp.rs:11-15, Cargo.toml:17
Implementation Details
The implementation of context_server_command is responsible for constructing the command that Zed uses to launch the MCP server.
Command Execution Sequence
The extension communicates with the server via stdio, passing "stdio" as the primary argument to the cu binary.
Sources: src/container_use_mcp.rs:65-88
Dependency Management
The project relies on specific versions of the Zed Extension API and serialization libraries:
- zed_extension_api:
0.5.0 - serde:
1.0 - schemars:
0.8
Sources: Cargo.toml:15-18
Agent Integration
For coding agents to effectively use the containerized environment, specific rules must be established. The extension provides instructions to project owners to include a .rules file at the root of their workspace.
- Action: Download agent rules from Dagger's
container-userepository. - Command:
curl -o .rules https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md
Sources: README.md:28-32, configuration/installation_instructions.md:1-1
Summary
The container-use-mcp extension provides a standardized way for Zed to interface with containerized coding environments. By leveraging the Model Context Protocol and managing the lifecycle of the cu binary, it enables secure, isolated execution contexts for AI agents, configurable through standard Zed settings and governed by specific project-level rules.