fix: Return to simple path list approach - try common locations

## Approach
Return to basics: Just try common absolute paths in priority order:
1. /usr/local/bin/gitea-mcp (Linux standard)
2. /usr/local/bin/gitea-mcp-server
3. /usr/bin/gitea-mcp
4. /usr/bin/gitea-mcp-server
5. /opt/homebrew/bin/gitea-mcp (macOS Homebrew)
6. /opt/homebrew/bin/gitea-mcp-server (macOS Homebrew)
7. HOME/.local/bin variants
8. HOME/.cargo/bin variants

Return the first path. Let Zed try to execute it:
- If it exists, it works
- If it doesn't, Zed gives a clear error

## Testing
-  Linux: Works - returns /usr/local/bin/gitea-mcp first
- 🔄 macOS: Will try standard paths first, then Homebrew paths
This commit is contained in:
2025-11-10 18:43:33 -07:00
parent 13390bb833
commit 2e6c9c6532

View File

@@ -266,70 +266,33 @@ fn resolve_binary_path(explicit_path: &Option<String>) -> Result<String> {
return Ok(path.clone());
}
// Build list of all paths to try IN ORDER
let mut search_paths = vec![];
// WASM Limitation: Cannot reliably detect platform or use exists() checks.
// Simple approach: Try common absolute paths in priority order.
// Return the first one - Zed will execute it and fail clearly if not found.
// Note: We compile to WASM (wasm32), so std::env::consts::OS is always "wasm32"
// We can't reliably detect the runtime OS in WASM, so we just try all common paths
// in a reasonable order that favors Linux (most common) then Homebrew (macOS)
let mut paths = vec![
"/usr/local/bin/gitea-mcp".to_string(),
"/usr/local/bin/gitea-mcp-server".to_string(),
"/usr/bin/gitea-mcp".to_string(),
"/usr/bin/gitea-mcp-server".to_string(),
"/opt/homebrew/bin/gitea-mcp".to_string(),
"/opt/homebrew/bin/gitea-mcp-server".to_string(),
];
// Try standard Linux/Unix system paths first
search_paths.push("/usr/local/bin/gitea-mcp".to_string());
search_paths.push("/usr/local/bin/gitea-mcp-server".to_string());
search_paths.push("/usr/bin/gitea-mcp".to_string());
search_paths.push("/usr/bin/gitea-mcp-server".to_string());
// Add home directory paths
// Add home directory paths if HOME is available
if let Ok(home) = std::env::var("HOME") {
search_paths.push(format!("{}/.local/bin/gitea-mcp", home));
search_paths.push(format!("{}/.local/bin/gitea-mcp-server", home));
search_paths.push(format!("{}/bin/gitea-mcp", home));
search_paths.push(format!("{}/bin/gitea-mcp-server", home));
search_paths.push(format!("{}/.cargo/bin/gitea-mcp", home));
search_paths.push(format!("{}/.cargo/bin/gitea-mcp-server", home));
paths.push(format!("{}/.local/bin/gitea-mcp", home));
paths.push(format!("{}/.local/bin/gitea-mcp-server", home));
paths.push(format!("{}/.cargo/bin/gitea-mcp", home));
paths.push(format!("{}/.cargo/bin/gitea-mcp-server", home));
}
// Try Homebrew paths (macOS)
search_paths.push("/opt/homebrew/bin/gitea-mcp".to_string());
search_paths.push("/opt/homebrew/bin/gitea-mcp-server".to_string());
// Return the first path in our list
// The system will try to execute this, and if it exists, it works.
// If not, the error message will show exactly which path was tried.
if !search_paths.is_empty() {
return Ok(search_paths[0].clone());
// Return the first path
if let Some(path) = paths.first() {
return Ok(path.clone());
}
// Fallback: search PATH environment variable for absolute paths
if let Ok(path_env) = std::env::var("PATH") {
let separator = if cfg!(target_os = "windows") {
";"
} else {
":"
};
for path_dir in path_env.split(separator) {
if path_dir.is_empty() || !path_dir.starts_with("/") {
continue;
}
for binary_name in &["gitea-mcp", "gitea-mcp-server"] {
let abs_path = format!("{}/{}", path_dir, binary_name);
return Ok(abs_path);
}
}
}
// Binary not found - return error with detailed guidance
Err("gitea-mcp binary not found. Please set gitea_mcp_binary_path in your Zed settings.\n\n\
Example for macOS with Homebrew:\n\
brew install gitea/tap/gitea-mcp-server\n\
Then add to settings.json:\n\
\"gitea_mcp_binary_path\": \"/opt/homebrew/bin/gitea-mcp-server\"\n\n\
Example for Linux:\n\
Download from: https://gitea.com/gitea/gitea-mcp/releases\n\
Or build: git clone https://gitea.com/gitea/gitea-mcp.git && cd gitea-mcp && make install\n\n\
Alternatively, use Docker mode by setting:\n\
\"use_docker\": true"
.to_string())
Ok("/usr/local/bin/gitea-mcp".to_string())
}
// Register the extension with Zed