Skip to content

Commit df14d84

Browse files
committed
Minor improvements for stdio bridge
- Consolidated the !useHttp && isRunning checks into a single shouldResume flag. - Wrapped the fire-and-forget StopAsync in a continuation that logs faults (matching the HTTP handler pattern). - Wrapped StartAsync in a continuation that logs failures and only triggers the health check on success.
1 parent 9e11b1d commit df14d84

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

MCPForUnity/Editor/Services/StdioBridgeReloadHandler.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@ private static void OnBeforeAssemblyReload()
2626
// Only persist resume intent when stdio is the active transport and the bridge is running.
2727
bool useHttp = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
2828
bool isRunning = MCPServiceLocator.TransportManager.IsRunning(TransportMode.Stdio);
29-
if (!useHttp && isRunning)
29+
bool shouldResume = !useHttp && isRunning;
30+
31+
if (shouldResume)
3032
{
3133
EditorPrefs.SetBool(EditorPrefKeys.ResumeStdioAfterReload, true);
34+
35+
// Stop only the stdio bridge; leave HTTP untouched if it is running concurrently.
36+
var stopTask = MCPServiceLocator.TransportManager.StopAsync(TransportMode.Stdio);
37+
stopTask.ContinueWith(t =>
38+
{
39+
if (t.IsFaulted && t.Exception != null)
40+
{
41+
McpLog.Warn($"Error stopping stdio bridge before reload: {t.Exception.GetBaseException()?.Message}");
42+
}
43+
}, System.Threading.Tasks.TaskScheduler.Default);
3244
}
3345
else
3446
{
3547
EditorPrefs.DeleteKey(EditorPrefKeys.ResumeStdioAfterReload);
3648
}
37-
38-
if (!useHttp && isRunning)
39-
{
40-
// Stop only the stdio bridge; leave HTTP untouched if it is running concurrently.
41-
MCPServiceLocator.TransportManager.StopAsync(TransportMode.Stdio);
42-
}
4349
}
4450
catch (Exception ex)
4551
{
@@ -76,15 +82,23 @@ private static void OnAfterAssemblyReload()
7682

7783
private static void TryStartBridgeImmediate()
7884
{
79-
try
85+
var startTask = MCPServiceLocator.TransportManager.StartAsync(TransportMode.Stdio);
86+
startTask.ContinueWith(t =>
8087
{
81-
MCPServiceLocator.TransportManager.StartAsync(TransportMode.Stdio);
88+
if (t.IsFaulted)
89+
{
90+
var baseEx = t.Exception?.GetBaseException();
91+
McpLog.Warn($"Failed to resume stdio bridge after reload: {baseEx?.Message}");
92+
return;
93+
}
94+
if (!t.Result)
95+
{
96+
McpLog.Warn("Failed to resume stdio bridge after domain reload");
97+
return;
98+
}
99+
82100
MCPForUnity.Editor.Windows.MCPForUnityEditorWindow.RequestHealthVerification();
83-
}
84-
catch (Exception ex)
85-
{
86-
McpLog.Warn($"Failed to resume stdio bridge after reload: {ex.Message}");
87-
}
101+
}, System.Threading.Tasks.TaskScheduler.Default);
88102
}
89103
}
90104
}

0 commit comments

Comments
 (0)