@@ -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}
0 commit comments