Skip to content

Commit 8694be6

Browse files
authored
Merge pull request #469 from IvanMurzak/feature/mcp-inspector-launcher
Refactor menu item labels and add MCP Inspector launch functionality
2 parents 6f9c430 + 7f07a7b commit 8694be6

1 file changed

Lines changed: 78 additions & 5 deletions

File tree

Unity-MCP-Plugin/Assets/root/Editor/Scripts/UI/MenuItems.cs

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
using com.IvanMurzak.Unity.MCP.Editor.Utils;
1616
using UnityEditor;
1717
using UnityEngine;
18+
using static com.IvanMurzak.McpPlugin.Common.Consts.MCP.Server;
1819

1920
namespace com.IvanMurzak.Unity.MCP.Editor.UI
2021
{
2122
public static class MenuItems
2223
{
23-
[MenuItem("Window/AI Game Developer (Unity-MCP) %&a", priority = 1006)]
24+
[MenuItem("Window/AI Game Developer MCP %&a", priority = 1006)]
2425
public static void ShowWindow() => MainWindowEditor.ShowWindow();
2526

2627
[MenuItem("Tools/AI Game Developer/Check for Updates", priority = 999)]
2728
public static void CheckForUpdates() => _ = UpdateChecker.CheckForUpdatesAsync(forceCheck: true);
2829

29-
[MenuItem("Tools/AI Game Developer/Download Server Binaries", priority = 1000)]
30+
[MenuItem("Tools/AI Game Developer/Server/Download Binaries", priority = 1000)]
3031
public static Task DownloadServer() => McpServerManager.DownloadAndUnpackBinary();
3132

32-
[MenuItem("Tools/AI Game Developer/Delete Server Binaries", priority = 1001)]
33+
[MenuItem("Tools/AI Game Developer/Server/Delete Binaries", priority = 1001)]
3334
public static void DeleteServer()
3435
{
3536
var result = McpServerManager.DeleteBinaryFolderIfExists();
@@ -57,12 +58,84 @@ public static void DeleteServer()
5758
}
5859
}
5960

60-
[MenuItem("Tools/AI Game Developer/Open Server Logs", priority = 1002)]
61+
[MenuItem("Tools/AI Game Developer/Server/Open Logs", priority = 1002)]
6162
public static void OpenServerLogs() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log.txt");
6263

63-
[MenuItem("Tools/AI Game Developer/Open Server Log errors", priority = 1003)]
64+
[MenuItem("Tools/AI Game Developer/Server/Open Log Errors", priority = 1003)]
6465
public static void OpenServerLogErrors() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log-error.txt");
6566

67+
[MenuItem("Tools/AI Game Developer/Server/Launch MCP Inspector", priority = 1004)]
68+
public static void LaunchMcpInspector()
69+
{
70+
if (UnityMcpPlugin.TransportMethod != TransportMethod.streamableHttp)
71+
{
72+
NotificationPopupWindow.Show(
73+
windowTitle: "Error",
74+
title: "HTTP Transport required",
75+
message: "The MCP Inspector can only be launched when the transport method is set to HTTP. Please change the transport method in the plugin settings and try again.",
76+
width: 350,
77+
minWidth: 350,
78+
height: 200,
79+
minHeight: 200);
80+
return;
81+
}
82+
83+
// Run command in a terminal window: npx @modelcontextprotocol/inspector http://localhost:8080 --transport http
84+
var npxArgs = $"-y @modelcontextprotocol/inspector {UnityMcpPlugin.Host} --transport http";
85+
Debug.Log($"Launching MCP Inspector with command: npx {npxArgs}");
86+
87+
var processInfo = new System.Diagnostics.ProcessStartInfo
88+
{
89+
FileName = "npx",
90+
Arguments = npxArgs,
91+
UseShellExecute = true,
92+
CreateNoWindow = false,
93+
};
94+
95+
try
96+
{
97+
System.Diagnostics.Process.Start(processInfo);
98+
}
99+
catch (System.ComponentModel.Win32Exception ex)
100+
{
101+
var command = $"{processInfo.FileName} {processInfo.Arguments}";
102+
NotificationPopupWindow.Show(
103+
windowTitle: "Launch Failed",
104+
title: "Unable to start MCP Inspector",
105+
message:
106+
"The MCP Inspector could not be started from Unity.\n\n" +
107+
"This usually means that Node.js (and npx) is not installed, or 'npx' is not available on your PATH.\n\n" +
108+
"Prerequisites:\n" +
109+
" - Install Node.js (which includes npx)\n" +
110+
" - Ensure 'npx' is available from your terminal/command prompt\n\n" +
111+
"You can try running the following command manually in a terminal:\n" +
112+
command + "\n\n" +
113+
"System error:\n" +
114+
ex.Message,
115+
width: 450,
116+
minWidth: 450,
117+
height: 460,
118+
minHeight: 460);
119+
}
120+
catch (System.Exception ex)
121+
{
122+
var command = $"{processInfo.FileName} {processInfo.Arguments}";
123+
NotificationPopupWindow.Show(
124+
windowTitle: "Launch Failed",
125+
title: "Unexpected error starting MCP Inspector",
126+
message:
127+
"An unexpected error occurred while trying to start the MCP Inspector.\n\n" +
128+
"You can try running the following command manually in a terminal:\n" +
129+
command + "\n\n" +
130+
"Error details:\n" +
131+
ex.Message,
132+
width: 450,
133+
minWidth: 450,
134+
height: 460,
135+
minHeight: 460);
136+
}
137+
}
138+
66139
[MenuItem("Tools/AI Game Developer/Debug/Show Update Popup", priority = 2000)]
67140
public static void ShowUpdatePopup() => UpdatePopupWindow.ShowWindow(UnityMcpPlugin.Version, "99.99.99");
68141

0 commit comments

Comments
 (0)