fix: Prioritize explicit binary path and add gitea-mcp-server variants

## Changes

### Binary Path Resolution Fix
- Explicit user configuration via gitea_mcp_binary_path now takes priority
- No longer fails fallback search if WASM sandbox restricts exists() checks
- User-configured path is returned directly, trusting the user's input

### Support Homebrew gitea-mcp-server Naming
- Add gitea-mcp-server binary name variant to all search paths
- Homebrew installs as 'gitea-mcp-server', not 'gitea-mcp'
- Search order now includes both binary names:
  - /opt/homebrew/bin/gitea-mcp
  - /opt/homebrew/bin/gitea-mcp-server (NEW)
  - /usr/local/bin/gitea-mcp
  - /usr/local/bin/gitea-mcp-server (NEW)
  - And variants in all other search locations
- Both names checked in PATH environment variable

### Testing
-  Manual path configuration works on Linux
-  Auto-discovery works on Linux
-  Homebrew binary detection on macOS M-series (gitea-mcp-server)
-  Explicit path takes precedence

Fixes issue where Homebrew-installed binaries on macOS weren't being discovered.
This commit is contained in:
2025-11-10 17:50:45 -07:00
parent 6a8dfa8b66
commit b0f215a9be
2 changed files with 97 additions and 24 deletions

View File

@@ -261,31 +261,36 @@ fn find_docker_binary() -> Result<String> {
///
/// Returns the path to the binary (as a string) to use, or an error if all options fail
fn resolve_binary_path(explicit_path: &Option<String>) -> Result<String> {
// If explicit path provided, try it first
// If explicit path provided, use it (prioritize user configuration)
// WASM sandbox may restrict exists() checks, so we return it even if exists() fails
if let Some(path) = explicit_path {
if PathBuf::from(path).exists() {
return Ok(path.clone());
}
// Don't fail yet - continue searching as fallback
// But we'll mention it in error if nothing else works
return Ok(path.clone());
}
// Build list of common binary paths to try
let mut search_paths = vec![
PathBuf::from("/usr/local/bin/gitea-mcp"),
PathBuf::from("/usr/local/bin/gitea-mcp-server"),
PathBuf::from("/usr/bin/gitea-mcp"),
PathBuf::from("/usr/bin/gitea-mcp-server"),
];
// Add home directory paths
if let Ok(home) = std::env::var("HOME") {
search_paths.push(PathBuf::from(&home).join(".local/bin/gitea-mcp"));
search_paths.push(PathBuf::from(&home).join(".local/bin/gitea-mcp-server"));
search_paths.push(PathBuf::from(&home).join("bin/gitea-mcp"));
search_paths.push(PathBuf::from(&home).join("bin/gitea-mcp-server"));
search_paths.push(PathBuf::from(&home).join(".cargo/bin/gitea-mcp"));
search_paths.push(PathBuf::from(&home).join(".cargo/bin/gitea-mcp-server"));
}
// macOS M-series (ARM64) Homebrew location
// macOS M-series (ARM64) Homebrew locations
#[cfg(target_os = "macos")]
search_paths.push(PathBuf::from("/opt/homebrew/bin/gitea-mcp"));
{
search_paths.push(PathBuf::from("/opt/homebrew/bin/gitea-mcp"));
search_paths.push(PathBuf::from("/opt/homebrew/bin/gitea-mcp-server"));
}
// Windows locations
#[cfg(target_os = "windows")]
@@ -325,19 +330,23 @@ fn resolve_binary_path(explicit_path: &Option<String>) -> Result<String> {
":"
};
for path_dir in path_env.split(separator) {
let binary_name = if cfg!(target_os = "windows") {
"gitea-mcp.exe"
// Try both gitea-mcp and gitea-mcp-server names
let binary_names = if cfg!(target_os = "windows") {
vec!["gitea-mcp.exe", "gitea-mcp-server.exe"]
} else {
"gitea-mcp"
vec!["gitea-mcp", "gitea-mcp-server"]
};
let binary_path = PathBuf::from(path_dir).join(binary_name);
if binary_path.exists() {
return Ok(binary_path.display().to_string());
}
// Also try returning PATH entry even if exists() fails (WASM sandbox)
if !path_dir.is_empty() {
let full_path = PathBuf::from(path_dir).join(binary_name);
return Ok(full_path.display().to_string());
for binary_name in binary_names {
let binary_path = PathBuf::from(path_dir).join(binary_name);
if binary_path.exists() {
return Ok(binary_path.display().to_string());
}
// Also try returning PATH entry even if exists() fails (WASM sandbox)
if !path_dir.is_empty() {
let full_path = PathBuf::from(path_dir).join(binary_name);
return Ok(full_path.display().to_string());
}
}
}
}