Skip to content

Commit cb4b03c

Browse files
committed
refactor: Improve npm command logging and settings initialization
1 parent 5e7f497 commit cb4b03c

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

Editor/UnityBridge/McpUnityEditorWindow.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@ private void DrawServerTab()
143143

144144
EditorGUILayout.Space();
145145

146-
// NPM Executable Path
147-
string newNpmPath = EditorGUILayout.TextField(new GUIContent("NPM Executable Path", "Optional: Full path to the npm executable (e.g., /Users/user/.asdf/shims/npm or C:\\path\\to\\npm.cmd). If not set, 'npm' from the system PATH will be used."), settings.NpmExecutablePath);
148-
if (newNpmPath != settings.NpmExecutablePath)
149-
{
150-
settings.NpmExecutablePath = newNpmPath;
151-
settings.SaveSettings();
152-
}
153-
154-
EditorGUILayout.Space();
155-
156146
// Server control buttons
157147
EditorGUILayout.BeginHorizontal();
158148

@@ -210,6 +200,16 @@ private void DrawServerTab()
210200
}
211201

212202
EditorGUILayout.EndVertical();
203+
204+
// NPM Executable Path
205+
string newNpmPath = EditorGUILayout.TextField(new GUIContent("NPM Executable Path", "Optional: Full path to the npm executable (e.g., /Users/user/.asdf/shims/npm or C:\\path\\to\\npm.cmd). If not set, 'npm' from the system PATH will be used."), settings.NpmExecutablePath);
206+
if (newNpmPath != settings.NpmExecutablePath)
207+
{
208+
settings.NpmExecutablePath = newNpmPath;
209+
settings.SaveSettings();
210+
}
211+
212+
EditorGUILayout.Space();
213213

214214
// MCP Config generation section
215215
EditorGUILayout.Space();

Editor/UnityBridge/McpUnitySettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public void LoadSettings()
7474
string json = File.ReadAllText(SettingsPath);
7575
JsonUtility.FromJsonOverwrite(json, this);
7676
}
77+
else
78+
{
79+
// Create default settings file on the first time initialization
80+
SaveSettings();
81+
}
7782
}
7883
catch (Exception ex)
7984
{

Editor/Utils/McpUtils.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,18 @@ public static void RunNpmCommand(string arguments, string workingDirectory)
354354

355355
if (process.ExitCode == 0)
356356
{
357-
Debug.Log($"[MCP Unity] npm {arguments} completed successfully in {workingDirectory}.");
357+
Debug.Log($"[MCP Unity] npm {arguments} completed successfully in {workingDirectory}.\n{output}");
358358
}
359359
else
360360
{
361-
Debug.LogError($"[MCP Unity] npm {arguments} failed in {workingDirectory}. Exit Code: {process.ExitCode}");
361+
Debug.LogError($"[MCP Unity] npm {arguments} failed in {workingDirectory}. Exit Code: {process.ExitCode}. Error: {error}");
362362
}
363-
364-
if (!string.IsNullOrEmpty(output)) Debug.Log($"[MCP Unity] Output:\n{output}");
365-
if (!string.IsNullOrEmpty(error)) Debug.LogError($"[MCP Unity] Error:\n{error}");
366363
}
367364
}
368-
catch (System.ComponentModel.Win32Exception ex) // Catch specific exception for "file not found"
369-
{
370-
Debug.LogError($"[MCP Unity] Failed to run npm command '{shellCommand} {shellArguments}'. Ensure Node.js and npm are installed and in your system's PATH. Error: {ex.Message}");
371-
}
372365
catch (Exception ex)
373366
{
374-
Debug.LogError($"[MCP Unity] Exception while running npm command '{shellCommand} {shellArguments}' in {workingDirectory}: {ex.Message}\nDetails: {ex.StackTrace}");
367+
// Use commandToLog here
368+
Debug.LogError($"[MCP Unity] Exception while running npm {arguments} in {workingDirectory}. Error: {ex.Message}");
375369
}
376370
}
377371
}

0 commit comments

Comments
 (0)