Skip to content

Commit 4a83b5c

Browse files
sharpninjaCopilot
andcommitted
Fix TODO loading wrong workspace on startup
Constructor's InitializeMcpEndpoint() was calling ApplyWorkspaceConnectionOptions() with a synthetic Default entry, which triggered SwitchWorkspaceConnectionAsync and set IsSwitchingWorkspace=true. When LoadWorkspaceConnectionsAsync later selected the saved workspace (RequestTracker), the switch was blocked by IsSwitchingWorkspace. Fix: Replace ApplyWorkspaceConnectionOptions() in constructor with direct picker population (no switch logic). The first real switch now comes from LoadWorkspaceConnectionsAsync, which has the actual catalog and saved workspace key. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a6dcc56 commit 4a83b5c

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/McpServerManager.Core/ViewModels/MainWindowViewModel.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,20 @@ private void InitializeMcpEndpoint(string mcpBaseUrl, string? initialApiKey = nu
402402

403403
_activeMcpBaseUrl = _defaultMcpBaseUrl;
404404

405-
ApplyWorkspaceConnectionOptions(
406-
new[]
407-
{
408-
WorkspaceConnectionOption.CreateDefault(_defaultMcpBaseUri, primaryWorkspaceRootPath: null, apiKey: _defaultMcpApiKey)
409-
},
410-
preferredSelection: null,
411-
preferredBaseUrl: _defaultMcpBaseUrl);
405+
// Pre-populate the workspace picker with a placeholder.
406+
// No switch is triggered here — the real switch happens in LoadWorkspaceConnectionsAsync
407+
// after the workspace catalog is fetched and the saved workspace key is resolved.
408+
var defaultOption = WorkspaceConnectionOption.CreateDefault(_defaultMcpBaseUri, primaryWorkspaceRootPath: null, _defaultMcpApiKey);
409+
WorkspaceConnections = new ObservableCollection<WorkspaceConnectionOption>(new[] { defaultOption });
410+
_suppressWorkspaceSelectionChanged = true;
411+
try
412+
{
413+
SelectedWorkspaceConnection = defaultOption;
414+
}
415+
finally
416+
{
417+
_suppressWorkspaceSelectionChanged = false;
418+
}
412419
}
413420

414421
private static string NormalizeMcpBaseUrl(string mcpBaseUrl)

0 commit comments

Comments
 (0)