@@ -46,6 +46,7 @@ import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
4646import { listFiles } from "../services/glob/list-files"
4747import { BrowserSession } from "../services/browser/BrowserSession"
4848import { McpHub } from "../services/mcp/McpHub"
49+ import { McpServerManager } from "../services/mcp/McpServerManager"
4950import { telemetryService } from "../services/telemetry/TelemetryService"
5051import { 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