Automatic Binary Detection
Relevant source files
The following files were used as context for generating this wiki page:
Automatic Binary Detection is a core mechanism in the zed-container-use-mcp extension designed to locate the cu (Container Use) executable on the host system. This system ensures that the Zed editor can seamlessly interface with the Model Context Protocol (MCP) server provided by the Container Use tool, even if the user has not explicitly configured a file path.
The detection logic prioritizes user-defined settings but falls back to environment scanning using system-level utilities. By automating this process, the extension reduces manual configuration requirements for users while maintaining the flexibility to use custom binary locations.
Sources: src/container_use_mcp.rs:1-12, README.md:1-15
Detection Hierarchy and Logic
The extension employs a multi-tiered approach to resolve the location of the cu binary. The resolution logic is encapsulated within the context_server_binary_path method of the ContainerUseMcpExtension struct.
Resolution Tiers
- Cached/Custom Path: The system first checks for an existing
cached_binary_path. This is populated either by a previous successful detection or by the user'ssettings.jsonvia thecu_pathparameter. - System PATH Search: If no valid path is cached or if the cached file does not exist, the extension executes a system command to locate the binary within the user's standard environment PATH.
- Error Handling: If both methods fail, the system returns a descriptive error guiding the user to installation instructions.
Sources: src/container_use_mcp.rs:26-52, extension.toml:13-16
The diagram illustrates the fallback logic used to ensure the cu binary is found before attempting to launch the MCP server.
Sources: src/container_use_mcp.rs:26-52
Component Architecture
The Extension Struct
The ContainerUseMcpExtension maintains the state of the detection process. It utilizes the zed_extension_api to interact with the Zed editor and the underlying operating system.
| Field | Type | Description |
|---|---|---|
cached_binary_path | Option<String> | Stores the resolved path to avoid repeated system calls. |
Sources: src/container_use_mcp.rs:16-19
System Integration
The extension declares the necessary permissions to execute system commands in its manifest. Specifically, it uses the which command to scan the environment.
[[capabilities]]
kind = "process:exec"
command = "which"
args = ["cu"]
Sources: extension.toml:13-16
Configuration and Settings
Users can override the automatic detection by providing a specific path in their Zed configuration. The extension parses these settings using the ContainerUseMcpSettings struct during the initialization of the context server command.
Configuration Schema
The settings are defined using the schemars and serde libraries to ensure type safety and generate JSON schemas for Zed.
| Setting | Type | Optional | Description |
|---|---|---|---|
cu_path | String | Yes | Custom absolute path to the cu binary. |
Sources: src/container_use_mcp.rs:11-14, README.md:17-29
Implementation Detail: Settings Extraction
if let Some(settings) = settings.settings {
if let Ok(custom_settings) = serde_json::from_value::<ContainerUseMcpSettings>(settings) {
if let Some(cu_path) = custom_settings.cu_path {
self.cached_binary_path = Some(cu_path);
}
}
}
This block demonstrates how user-provided settings are injected into the detection cache before the binary resolution logic is triggered.
Sources: src/container_use_mcp.rs:65-72
Execution Flow
The detection process is triggered as part of the context_server_command lifecycle. This ensures the binary is located immediately before Zed attempts to spawn the MCP server process using the stdio transport.
The sequence diagram shows the interaction between Zed settings, the extension logic, and the OS environment during server startup.
Sources: src/container_use_mcp.rs:56-78
Summary
Automatic Binary Detection in zed-container-use-mcp provides a robust "zero-config" experience by leveraging system PATH resolution while maintaining support for custom installations. By caching results and integrating with Zed's settings API, the system balances performance with flexibility, ensuring the cu binary is reliably available for containerized agent operations.