Skip to content

Commit 392a182

Browse files
author
Miguel Cartier
committed
fix: Now the MCP can run in MacOS machines with node installed via homebrew
1 parent fbbb592 commit 392a182

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Editor/Utils/McpUtils.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,23 @@ public static void RunNpmCommand(string arguments, string workingDirectory)
386386
}
387387
else // macOS / Linux
388388
{
389-
// Fallback to /bin/bash to find 'npm' in PATH
390-
startInfo.FileName = "/bin/bash";
391-
startInfo.Arguments = $"-c \"npm {arguments}\"";
389+
string userShell = Environment.GetEnvironmentVariable("SHELL") ?? "/bin/bash";
390+
string shellName = Path.GetFileName(userShell);
391+
392+
// Source rc file to init version managers (nvm, fnm, volta) - GUI apps don't inherit shell env
393+
string rcFile = shellName == "zsh" ? ".zshrc" : ".bashrc";
394+
395+
startInfo.FileName = userShell;
396+
startInfo.Arguments = $"-c \"source ~/{rcFile} 2>/dev/null || true; npm {arguments}\"";
392397

393-
// Ensure PATH includes common npm locations and current PATH
398+
// Fallback PATH for common npm locations
394399
string currentPath = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
395-
string extraPaths = "/usr/local/bin:/opt/homebrew/bin";
400+
string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
401+
string extraPaths = string.Join(":",
402+
"/usr/local/bin",
403+
"/opt/homebrew/bin",
404+
$"{homeDir}/.nvm/versions/node/default/bin" // nvm default alias
405+
);
396406
startInfo.EnvironmentVariables["PATH"] = $"{extraPaths}:{currentPath}";
397407
}
398408

0 commit comments

Comments
 (0)