Browse Source

Fix MCP hub lookup during view transition (#2829)

Matt Rubens 8 months ago
parent
commit
8b5d48013e
1 changed files with 11 additions and 3 deletions
  1. 11 3
      src/core/Cline.ts

+ 11 - 3
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<ClineEvents> {
 		this.lastApiRequestTime = Date.now()
 
 		if (mcpEnabled ?? true) {
-			mcpHub = this.providerRef.deref()?.getMcpHub()
+			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("MCP hub not available")
+				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")
 			})
 		}