Skip to content

Commit d02c5ec

Browse files
committed
feat: persist server installation errors and show retry UI instead of auto-marking as handled
1 parent ff2c15c commit d02c5ec

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

MCPForUnity/Editor/Helpers/PackageLifecycleManager.cs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static class PackageLifecycleManager
1414
{
1515
private const string VersionKeyPrefix = "MCPForUnity.InstalledVersion:";
1616
private const string LegacyInstallFlagKey = "MCPForUnity.ServerInstalled"; // For migration
17+
private const string InstallErrorKeyPrefix = "MCPForUnity.InstallError:"; // Stores last installation error
1718

1819
static PackageLifecycleManager()
1920
{
@@ -83,17 +84,17 @@ private static void PerformInstallation(string version, string versionKey, bool
8384
error = ex.Message;
8485
capturedEx = ex;
8586

86-
// Mark as handled to avoid repeated failures
87-
EditorPrefs.SetBool(versionKey, true);
88-
if (isFirstTimeInstall)
89-
{
90-
EditorPrefs.SetBool(LegacyInstallFlagKey, true);
91-
}
87+
// Store the error for display in the UI, but don't mark as handled
88+
// This allows the user to manually rebuild via the "Rebuild Server" button
89+
string errorKey = InstallErrorKeyPrefix + version;
90+
EditorPrefs.SetString(errorKey, ex.Message ?? "Unknown error");
91+
92+
// Don't mark as installed - user needs to manually rebuild
9293
}
9394

9495
if (!string.IsNullOrEmpty(error))
9596
{
96-
McpLog.Info($"Server check: {error}. Download via Window > MCP For Unity if needed.", always: false);
97+
McpLog.Info($"Server installation failed: {error}. Use Window > MCP For Unity > Rebuild Server to retry.", always: false);
9798
}
9899
}
99100

@@ -201,5 +202,41 @@ private static void CleanupLegacyPrefs()
201202
}
202203
catch { }
203204
}
205+
206+
/// <summary>
207+
/// Gets the last installation error for the current package version, if any.
208+
/// Returns null if there was no error or the error has been cleared.
209+
/// </summary>
210+
public static string GetLastInstallError()
211+
{
212+
try
213+
{
214+
string currentVersion = GetPackageVersion();
215+
string errorKey = InstallErrorKeyPrefix + currentVersion;
216+
if (EditorPrefs.HasKey(errorKey))
217+
{
218+
return EditorPrefs.GetString(errorKey, null);
219+
}
220+
}
221+
catch { }
222+
return null;
223+
}
224+
225+
/// <summary>
226+
/// Clears the last installation error. Should be called after a successful manual rebuild.
227+
/// </summary>
228+
public static void ClearLastInstallError()
229+
{
230+
try
231+
{
232+
string currentVersion = GetPackageVersion();
233+
string errorKey = InstallErrorKeyPrefix + currentVersion;
234+
if (EditorPrefs.HasKey(errorKey))
235+
{
236+
EditorPrefs.DeleteKey(errorKey);
237+
}
238+
}
239+
catch { }
240+
}
204241
}
205242
}

MCPForUnity/Editor/Helpers/ServerInstaller.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ public static bool RebuildMcpServer()
488488
}
489489

490490
McpLog.Info($"Server rebuilt successfully at {destRoot} (version {embeddedVer})");
491+
492+
// Clear any previous installation error
493+
PackageLifecycleManager.ClearLastInstallError();
494+
491495
return true;
492496
}
493497
catch (Exception ex)

MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,15 @@ private void UpdateServerStatusBanner()
641641
rebuildServerButton.style.display = DisplayStyle.None;
642642
}
643643

644+
// Check for installation errors first
645+
string installError = PackageLifecycleManager.GetLastInstallError();
646+
if (!string.IsNullOrEmpty(installError))
647+
{
648+
serverStatusMessage.text = $"\u274C Server installation failed: {installError}. Click 'Rebuild Server' to retry.";
649+
serverStatusBanner.style.display = DisplayStyle.Flex;
650+
}
644651
// Update banner
645-
if (!hasEmbedded && string.IsNullOrEmpty(installedVer))
652+
else if (!hasEmbedded && string.IsNullOrEmpty(installedVer))
646653
{
647654
serverStatusMessage.text = "\u26A0 Server not installed. Click 'Download & Install Server' to get started.";
648655
serverStatusBanner.style.display = DisplayStyle.Flex;

0 commit comments

Comments
 (0)