Fix MCP hub lookup during view transition (#2829)

This commit is contained in:
Matt Rubens 2025-04-21 22:39:39 -04:00 committed by GitHub
parent b6ea9d1465
commit 8b5d48013e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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()
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")
})
}