forked from IvanMurzak/Unity-MCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuItems.cs
More file actions
171 lines (155 loc) · 7.62 KB
/
MenuItems.cs
File metadata and controls
171 lines (155 loc) · 7.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
┌──────────────────────────────────────────────────────────────────┐
│ Author: Ivan Murzak (https://github.com/IvanMurzak) │
│ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │
│ Copyright (c) 2025 Ivan Murzak │
│ Licensed under the Apache License, Version 2.0. │
│ See the LICENSE file in the project root for more information. │
└──────────────────────────────────────────────────────────────────┘
*/
#nullable enable
#if UNITY_EDITOR
using System.IO;
using System.Threading.Tasks;
using com.IvanMurzak.Unity.MCP.Editor.Utils;
using UnityEditor;
using UnityEngine;
using static com.IvanMurzak.McpPlugin.Common.Consts.MCP.Server;
namespace com.IvanMurzak.Unity.MCP.Editor.UI
{
public static class MenuItems
{
[MenuItem("Window/AI Game Developer — MCP %&a", priority = 1006)]
public static void ShowWindow() => MainWindowEditor.ShowWindow();
[MenuItem("Tools/AI Game Developer/Check for Updates", priority = 999)]
public static void CheckForUpdates() => _ = UpdateChecker.CheckForUpdatesAsync(forceCheck: true);
[MenuItem("Tools/AI Game Developer/Server/Download Binaries", priority = 1000)]
public static Task DownloadServer() => McpServerManager.DownloadAndUnpackBinary();
[MenuItem("Tools/AI Game Developer/Server/Delete Binaries", priority = 1001)]
public static void DeleteServer()
{
var result = McpServerManager.DeleteBinaryFolderIfExists();
if (result)
{
NotificationPopupWindow.Show(
windowTitle: "Success",
title: "MCP Server Binaries Deleted",
message: "The MCP server binaries were successfully deleted. You can download them again from the Tools menu.",
width: 350,
minWidth: 350,
height: 200,
minHeight: 200);
}
else
{
NotificationPopupWindow.Show(
windowTitle: "Error",
title: "MCP Server Binaries Not Found",
message: "No MCP server binaries were found to delete. They may have already been deleted or were never downloaded.",
width: 350,
minWidth: 350,
height: 200,
minHeight: 200);
}
}
[MenuItem("Tools/AI Game Developer/Server/Open Logs", priority = 1002)]
public static void OpenServerLogs() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log.txt");
[MenuItem("Tools/AI Game Developer/Server/Open Log Errors", priority = 1003)]
public static void OpenServerLogErrors() => OpenFile(McpServerManager.ExecutableFolderPath + "/logs/server-log-error.txt");
[MenuItem("Tools/AI Game Developer/Server/Launch MCP Inspector", priority = 1004)]
public static void LaunchMcpInspector()
{
if (UnityMcpPluginEditor.TransportMethod != TransportMethod.streamableHttp)
{
NotificationPopupWindow.Show(
windowTitle: "Error",
title: "HTTP Transport required",
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.",
width: 350,
minWidth: 350,
height: 200,
minHeight: 200);
return;
}
// Run command in a terminal window: npx @modelcontextprotocol/inspector http://localhost:8080 --transport http
var npxArgs = $"-y @modelcontextprotocol/inspector {UnityMcpPluginEditor.Host} --transport http";
Debug.Log($"Launching MCP Inspector with command: npx {npxArgs}");
var processInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "npx",
Arguments = npxArgs,
UseShellExecute = true,
CreateNoWindow = false,
};
try
{
System.Diagnostics.Process.Start(processInfo);
}
catch (System.ComponentModel.Win32Exception ex)
{
var command = $"{processInfo.FileName} {processInfo.Arguments}";
NotificationPopupWindow.Show(
windowTitle: "Launch Failed",
title: "Unable to start MCP Inspector",
message:
"The MCP Inspector could not be started from Unity.\n\n" +
"This usually means that Node.js (and npx) is not installed, or 'npx' is not available on your PATH.\n\n" +
"Prerequisites:\n" +
" - Install Node.js (which includes npx)\n" +
" - Ensure 'npx' is available from your terminal/command prompt\n\n" +
"You can try running the following command manually in a terminal:\n" +
command + "\n\n" +
"System error:\n" +
ex.Message,
width: 450,
minWidth: 450,
height: 460,
minHeight: 460);
}
catch (System.Exception ex)
{
var command = $"{processInfo.FileName} {processInfo.Arguments}";
NotificationPopupWindow.Show(
windowTitle: "Launch Failed",
title: "Unexpected error starting MCP Inspector",
message:
"An unexpected error occurred while trying to start the MCP Inspector.\n\n" +
"You can try running the following command manually in a terminal:\n" +
command + "\n\n" +
"Error details:\n" +
ex.Message,
width: 450,
minWidth: 450,
height: 460,
minHeight: 460);
}
}
[MenuItem("Tools/AI Game Developer/Debug/Show Update Popup", priority = 2000)]
public static void ShowUpdatePopup() => UpdatePopupWindow.ShowWindow(UnityMcpPlugin.Version, "99.99.99");
[MenuItem("Tools/AI Game Developer/Debug/Reset Update Preferences", priority = 2001)]
public static void ResetUpdatePreferences()
{
UpdateChecker.ClearPreferences();
Debug.Log("Update preferences have been reset.");
}
[MenuItem("Tools/AI Game Developer/Debug/Serialization Check", priority = 2002)]
public static void ShowSerializationCheck() => SerializationCheckWindow.ShowWindow();
[MenuItem("Tools/AI Game Developer/Reset Config", priority = 2020)]
public static void ResetConfig()
{
UnityMcpPluginEditor.ResetConfig();
// Reload Domain to ensure all changes are picked up.
EditorUtility.RequestScriptReload();
}
static void OpenFile(string path)
{
if (!File.Exists(path))
{
Debug.LogWarning($"File not found: {path}");
return;
}
Application.OpenURL(path);
}
}
}
#endif