@@ -108,7 +108,12 @@ export class ConnectClusterTool extends AtlasToolBase {
108108 return cn . toString ( ) ;
109109 }
110110
111- private async connectToCluster ( connectionString : string , tryCount : number ) : Promise < void > {
111+ private async connectToCluster (
112+ projectId : string ,
113+ clusterName : string ,
114+ connectionString : string ,
115+ tryCount : number
116+ ) : Promise < void > {
112117 let lastError : Error | undefined = undefined ;
113118
114119 logger . debug (
@@ -118,7 +123,11 @@ export class ConnectClusterTool extends AtlasToolBase {
118123 ) ;
119124
120125 for ( let i = 0 ; i < tryCount ; i ++ ) {
121- if ( ! this . session . connectedAtlasCluster ) {
126+ if (
127+ ! this . session . connectedAtlasCluster ||
128+ this . session . connectedAtlasCluster . projectId != projectId ||
129+ this . session . connectedAtlasCluster . clusterName != clusterName
130+ ) {
122131 lastError = new Error ( "Cluster connection aborted" ) ;
123132 break ;
124133 }
@@ -225,7 +234,7 @@ export class ConnectClusterTool extends AtlasToolBase {
225234 try {
226235 // First, try to connect to the cluster within the current tool call.
227236 // We give it 60 attempts with 500 ms delay between each, so ~30 seconds
228- await this . connectToCluster ( connectionString , 60 ) ;
237+ await this . connectToCluster ( projectId , clusterName , connectionString , 60 ) ;
229238
230239 return {
231240 content : [
@@ -249,7 +258,7 @@ export class ConnectClusterTool extends AtlasToolBase {
249258 // return well before that.
250259 //
251260 // Once we add support for streamable http, we'd want to use progress notifications here.
252- void this . connectToCluster ( connectionString , 600 ) . catch ( ( err ) => {
261+ void this . connectToCluster ( projectId , clusterName , connectionString , 600 ) . catch ( ( err ) => {
253262 const error = err instanceof Error ? err : new Error ( String ( err ) ) ;
254263 logger . debug (
255264 LogId . atlasConnectFailure ,
0 commit comments