Skip to content

Commit d463aa5

Browse files
committed
Fix: Resolve absolute path for uvx to support Claude Desktop on macOS
Claude Desktop on macOS does not inherit the user's full PATH, causing 'spawn uvx ENOENT' errors when it tries to run the server. This change adds auto-discovery logic to find 'uvx' in common locations (like ~/.local/bin, ~/.cargo/bin, /opt/homebrew/bin) and writes the absolute path to the config. Also updated README with troubleshooting steps.
1 parent e613607 commit d463aa5

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

MCPForUnity/Editor/Helpers/ExecPath.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,56 @@ private static string ResolveClaudeFromNvm(string home)
132132
catch { return null; }
133133
}
134134

135+
// Resolve uvx absolute path. Pref -> env -> common locations -> PATH.
136+
internal static string ResolveUvx()
137+
{
138+
try
139+
{
140+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
141+
{
142+
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty;
143+
string[] candidates =
144+
{
145+
Path.Combine(home, ".local", "bin", "uvx"),
146+
Path.Combine(home, ".cargo", "bin", "uvx"),
147+
"/usr/local/bin/uvx",
148+
"/opt/homebrew/bin/uvx",
149+
"/usr/bin/uvx"
150+
};
151+
foreach (string c in candidates) { if (File.Exists(c)) return c; }
152+
153+
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
154+
return Which("uvx", "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin");
155+
#else
156+
return null;
157+
#endif
158+
}
159+
160+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
161+
{
162+
#if UNITY_EDITOR_WIN
163+
string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
164+
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
165+
166+
string[] candidates =
167+
{
168+
Path.Combine(userProfile, ".cargo", "bin", "uvx.exe"),
169+
Path.Combine(localAppData, "uv", "uvx.exe"),
170+
Path.Combine(userProfile, "uv", "uvx.exe"),
171+
};
172+
foreach (string c in candidates) { if (File.Exists(c)) return c; }
173+
174+
string fromWhere = Where("uvx.exe") ?? Where("uvx");
175+
if (!string.IsNullOrEmpty(fromWhere)) return fromWhere;
176+
#endif
177+
return null;
178+
}
179+
}
180+
catch { }
181+
182+
return null;
183+
}
184+
135185
// Explicitly set the Claude CLI absolute path override in EditorPrefs
136186
internal static void SetClaudeCliPath(string absolutePath)
137187
{

MCPForUnity/Editor/Services/PathResolverService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public string GetUvxPath()
3434
McpLog.Debug("No uvx path override found, falling back to default command");
3535
}
3636

37+
// Auto-discovery of absolute path
38+
string discovered = ExecPath.ResolveUvx();
39+
if (!string.IsNullOrEmpty(discovered))
40+
{
41+
return discovered;
42+
}
43+
3744
return "uvx";
3845
}
3946

MCPForUnity/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ Notes:
8282
- Help: [Fix MCP for Unity with Cursor, VS Code & Windsurf](https://github.com/CoplayDev/unity-mcp/wiki/1.-Fix-Unity-MCP-and-Cursor,-VSCode-&-Windsurf)
8383
- Claude CLI not found:
8484
- Help: [Fix MCP for Unity with Claude Code](https://github.com/CoplayDev/unity-mcp/wiki/2.-Fix-Unity-MCP-and-Claude-Code)
85+
- Claude Desktop "spawn uvx ENOENT" error on macOS:
86+
- Claude Desktop may not inherit your shell's PATH.
87+
- The MCP for Unity plugin attempts to automatically resolve the absolute path to `uvx`.
88+
- If this fails, use the "Choose UV Install Location" button in the MCP for Unity window to select your `uvx` executable (typically `~/.local/bin/uvx`), or manually update your Claude Desktop config to use the absolute path to `uvx`.
8589

8690
---
8791

0 commit comments

Comments
 (0)