|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Diagnostics; |
3 | 4 | using System.IO; |
4 | 5 | using System.Linq; |
@@ -34,6 +35,12 @@ public string GetUvxPath() |
34 | 35 | McpLog.Debug("No uvx path override found, falling back to default command"); |
35 | 36 | } |
36 | 37 |
|
| 38 | + string discovered = ResolveUvxFromSystem(); |
| 39 | + if (!string.IsNullOrEmpty(discovered)) |
| 40 | + { |
| 41 | + return discovered; |
| 42 | + } |
| 43 | + |
37 | 44 | return "uvx"; |
38 | 45 | } |
39 | 46 |
|
@@ -123,6 +130,81 @@ public bool IsClaudeCliDetected() |
123 | 130 | return !string.IsNullOrEmpty(GetClaudeCliPath()); |
124 | 131 | } |
125 | 132 |
|
| 133 | + private static string ResolveUvxFromSystem() |
| 134 | + { |
| 135 | + try |
| 136 | + { |
| 137 | + foreach (string candidate in EnumerateUvxCandidates()) |
| 138 | + { |
| 139 | + if (!string.IsNullOrEmpty(candidate) && File.Exists(candidate)) |
| 140 | + { |
| 141 | + return candidate; |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + catch |
| 146 | + { |
| 147 | + // fall back to bare command |
| 148 | + } |
| 149 | + |
| 150 | + return null; |
| 151 | + } |
| 152 | + |
| 153 | + private static IEnumerable<string> EnumerateUvxCandidates() |
| 154 | + { |
| 155 | + string exeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "uvx.exe" : "uvx"; |
| 156 | + |
| 157 | + string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
| 158 | + if (!string.IsNullOrEmpty(home)) |
| 159 | + { |
| 160 | + yield return Path.Combine(home, ".local", "bin", exeName); |
| 161 | + yield return Path.Combine(home, ".cargo", "bin", exeName); |
| 162 | + } |
| 163 | + |
| 164 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
| 165 | + { |
| 166 | + yield return "/opt/homebrew/bin/" + exeName; |
| 167 | + yield return "/usr/local/bin/" + exeName; |
| 168 | + } |
| 169 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
| 170 | + { |
| 171 | + yield return "/usr/local/bin/" + exeName; |
| 172 | + yield return "/usr/bin/" + exeName; |
| 173 | + } |
| 174 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 175 | + { |
| 176 | + string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); |
| 177 | + string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); |
| 178 | + |
| 179 | + if (!string.IsNullOrEmpty(localAppData)) |
| 180 | + { |
| 181 | + yield return Path.Combine(localAppData, "Programs", "uv", exeName); |
| 182 | + } |
| 183 | + |
| 184 | + if (!string.IsNullOrEmpty(programFiles)) |
| 185 | + { |
| 186 | + yield return Path.Combine(programFiles, "uv", exeName); |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + string pathEnv = Environment.GetEnvironmentVariable("PATH"); |
| 191 | + if (!string.IsNullOrEmpty(pathEnv)) |
| 192 | + { |
| 193 | + foreach (string rawDir in pathEnv.Split(Path.PathSeparator)) |
| 194 | + { |
| 195 | + if (string.IsNullOrWhiteSpace(rawDir)) continue; |
| 196 | + string dir = rawDir.Trim(); |
| 197 | + yield return Path.Combine(dir, exeName); |
| 198 | + |
| 199 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 200 | + { |
| 201 | + // Some PATH entries may already contain the file without extension |
| 202 | + yield return Path.Combine(dir, "uvx"); |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + |
126 | 208 | public void SetUvxPathOverride(string path) |
127 | 209 | { |
128 | 210 | if (string.IsNullOrEmpty(path)) |
|
0 commit comments