Skip to content

Commit 8b5d480

Browse files
authored
Fix MCP hub lookup during view transition (#2829)
1 parent b6ea9d1 commit 8b5d480

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/core/Cline.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
4646
import { listFiles } from "../services/glob/list-files"
4747
import { BrowserSession } from "../services/browser/BrowserSession"
4848
import { McpHub } from "../services/mcp/McpHub"
49+
import { McpServerManager } from "../services/mcp/McpServerManager"
4950
import { telemetryService } from "../services/telemetry/TelemetryService"
5051
import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../services/checkpoints"
5152

@@ -969,12 +970,19 @@ export class Cline extends EventEmitter<ClineEvents> {
969970
this.lastApiRequestTime = Date.now()
970971

971972
if (mcpEnabled ?? true) {
972-
mcpHub = this.providerRef.deref()?.getMcpHub()
973+
const provider = this.providerRef.deref()
974+
if (!provider) {
975+
throw new Error("Provider reference lost during view transition")
976+
}
977+
978+
// Wait for MCP hub initialization through McpServerManager
979+
mcpHub = await McpServerManager.getInstance(provider.context, provider)
973980
if (!mcpHub) {
974-
throw new Error("MCP hub not available")
981+
throw new Error("Failed to get MCP hub from server manager")
975982
}
983+
976984
// Wait for MCP servers to be connected before generating system prompt
977-
await pWaitFor(() => mcpHub!.isConnecting !== true, { timeout: 10_000 }).catch(() => {
985+
await pWaitFor(() => !mcpHub!.isConnecting, { timeout: 10_000 }).catch(() => {
978986
console.error("MCP servers failed to connect in time")
979987
})
980988
}

0 commit comments

Comments
 (0)