|
15 | 15 | using com.IvanMurzak.Unity.MCP.Editor.Utils; |
16 | 16 | using UnityEditor; |
17 | 17 | using UnityEngine; |
| 18 | +using static com.IvanMurzak.McpPlugin.Common.Consts.MCP.Server; |
18 | 19 |
|
19 | 20 | namespace com.IvanMurzak.Unity.MCP.Editor.UI |
20 | 21 | { |
21 | 22 | public static class MenuItems |
22 | 23 | { |
23 | | - [MenuItem("Window/AI Game Developer (Unity-MCP) %&a", priority = 1006)] |
| 24 | + [MenuItem("Window/AI Game Developer — MCP %&a", priority = 1006)] |
24 | 25 | public static void ShowWindow() => MainWindowEditor.ShowWindow(); |
25 | 26 |
|
26 | 27 | [MenuItem("Tools/AI Game Developer/Check for Updates", priority = 999)] |
27 | 28 | public static void CheckForUpdates() => _ = UpdateChecker.CheckForUpdatesAsync(forceCheck: true); |
28 | 29 |
|
29 | | - [MenuItem("Tools/AI Game Developer/Download Server Binaries", priority = 1000)] |
| 30 | + [MenuItem("Tools/AI Game Developer/Server/Download Binaries", priority = 1000)] |
30 | 31 | public static Task DownloadServer() => McpServerManager.DownloadAndUnpackBinary(); |
31 | 32 |
|
32 | | - [MenuItem("Tools/AI Game Developer/Delete Server Binaries", priority = 1001)] |
| 33 | + [MenuItem("Tools/AI Game Developer/Server/Delete Binaries", priority = 1001)] |
33 | 34 | public static void DeleteServer() |
34 | 35 | { |
35 | 36 | var result = McpServerManager.DeleteBinaryFolderIfExists(); |
@@ -57,12 +58,84 @@ public static void DeleteServer() |
57 | 58 | } |
58 | 59 | } |
59 | 60 |
|
60 | | - [MenuItem("Tools/AI Game Developer/Open Server Logs", priority = 1002)] |
| 61 | + [MenuItem("Tools/AI Game Developer/Server/Open Logs", priority = 1002)] |
61 | 62 | public static void OpenServerLogs() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log.txt"); |
62 | 63 |
|
63 | | - [MenuItem("Tools/AI Game Developer/Open Server Log errors", priority = 1003)] |
| 64 | + [MenuItem("Tools/AI Game Developer/Server/Open Log Errors", priority = 1003)] |
64 | 65 | public static void OpenServerLogErrors() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log-error.txt"); |
65 | 66 |
|
| 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 | + |
66 | 139 | [MenuItem("Tools/AI Game Developer/Debug/Show Update Popup", priority = 2000)] |
67 | 140 | public static void ShowUpdatePopup() => UpdatePopupWindow.ShowWindow(UnityMcpPlugin.Version, "99.99.99"); |
68 | 141 |
|
|
0 commit comments