Skip to content

Commit ad902b0

Browse files
sharpninjaCopilot
andcommitted
Fix VM guardrail regression for agent stream
Move McpAgentEventStreamService construction out of MainWindowViewModel into a core factory helper so architecture compliance baseline remains unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5cd723b commit ad902b0

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace McpServerManager.Core.Services;
4+
5+
/// <summary>
6+
/// Builds configured <see cref="McpAgentEventStreamService"/> instances outside ViewModel composition.
7+
/// </summary>
8+
internal static class AgentEventStreamFactory
9+
{
10+
public static McpAgentEventStreamService Create(
11+
string baseUrl,
12+
string? apiKey,
13+
string? bearerToken,
14+
Func<string>? resolveBaseUrl,
15+
Func<string?>? resolveBearerToken,
16+
Func<string?>? resolveApiKey,
17+
Func<string?>? resolveWorkspacePath)
18+
{
19+
var service = new McpAgentEventStreamService(baseUrl, apiKey, bearerToken)
20+
{
21+
ResolveBaseUrl = resolveBaseUrl,
22+
ResolveBearerToken = resolveBearerToken,
23+
ResolveApiKey = resolveApiKey,
24+
ResolveWorkspacePath = resolveWorkspacePath
25+
};
26+
27+
return service;
28+
}
29+
}

src/McpServerManager.Core/ViewModels/MainWindowViewModel.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,15 @@ private void InitializeMcpEndpoint(string mcpBaseUrl, string? initialApiKey = nu
409409
_mcpWorkspaceService = new McpWorkspaceService(_mcpClient, _defaultMcpBaseUri);
410410

411411
_activeMcpBaseUrl = _defaultMcpBaseUrl;
412-
_agentEventStreamService = new McpAgentEventStreamService(
412+
_agentEventStreamService = AgentEventStreamFactory.Create(
413413
_activeMcpBaseUrl,
414414
apiKey: _defaultMcpApiKey,
415-
bearerToken: _activeBearerToken)
416-
{
417-
ResolveBaseUrl = () => _activeMcpBaseUrl,
418-
ResolveBearerToken = () => _activeBearerToken,
419-
ResolveApiKey = () => _defaultMcpApiKey,
420-
ResolveWorkspacePath = () => SelectedWorkspaceConnection?.WorkspaceRootPath
421-
?? _mcpClient.WorkspacePath
422-
};
415+
bearerToken: _activeBearerToken,
416+
resolveBaseUrl: () => _activeMcpBaseUrl,
417+
resolveBearerToken: () => _activeBearerToken,
418+
resolveApiKey: () => _defaultMcpApiKey,
419+
resolveWorkspacePath: () => SelectedWorkspaceConnection?.WorkspaceRootPath
420+
?? _mcpClient.WorkspacePath);
423421

424422
// Pre-populate the workspace picker with a placeholder.
425423
// No switch is triggered here — the real switch happens in LoadWorkspaceConnectionsAsync

0 commit comments

Comments
 (0)