From 8b5d48013e0724bed5b0cc0acb663af50b8aa2bf Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 21 Apr 2025 22:39:39 -0400 Subject: [PATCH] Fix MCP hub lookup during view transition (#2829) --- src/core/Cline.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 4e5ee7f882..9a936f9698 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -46,6 +46,7 @@ import { UrlContentFetcher } from "../services/browser/UrlContentFetcher" import { listFiles } from "../services/glob/list-files" import { BrowserSession } from "../services/browser/BrowserSession" import { McpHub } from "../services/mcp/McpHub" +import { McpServerManager } from "../services/mcp/McpServerManager" import { telemetryService } from "../services/telemetry/TelemetryService" import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../services/checkpoints" @@ -969,12 +970,19 @@ export class Cline extends EventEmitter { this.lastApiRequestTime = Date.now() if (mcpEnabled ?? true) { - mcpHub = this.providerRef.deref()?.getMcpHub() - if (!mcpHub) { - throw new Error("MCP hub not available") + const provider = this.providerRef.deref() + if (!provider) { + throw new Error("Provider reference lost during view transition") } + + // Wait for MCP hub initialization through McpServerManager + mcpHub = await McpServerManager.getInstance(provider.context, provider) + if (!mcpHub) { + throw new Error("Failed to get MCP hub from server manager") + } + // Wait for MCP servers to be connected before generating system prompt - await pWaitFor(() => mcpHub!.isConnecting !== true, { timeout: 10_000 }).catch(() => { + await pWaitFor(() => !mcpHub!.isConnecting, { timeout: 10_000 }).catch(() => { console.error("MCP servers failed to connect in time") }) }