@@ -108,7 +108,12 @@ export class ConnectClusterTool extends AtlasToolBase {
108
108
return cn . toString ( ) ;
109
109
}
110
110
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 > {
112
117
let lastError : Error | undefined = undefined ;
113
118
114
119
logger . debug (
@@ -118,7 +123,11 @@ export class ConnectClusterTool extends AtlasToolBase {
118
123
) ;
119
124
120
125
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
+ ) {
122
131
lastError = new Error ( "Cluster connection aborted" ) ;
123
132
break ;
124
133
}
@@ -225,7 +234,7 @@ export class ConnectClusterTool extends AtlasToolBase {
225
234
try {
226
235
// First, try to connect to the cluster within the current tool call.
227
236
// 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 ) ;
229
238
230
239
return {
231
240
content : [
@@ -249,7 +258,7 @@ export class ConnectClusterTool extends AtlasToolBase {
249
258
// return well before that.
250
259
//
251
260
// 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 ) => {
253
262
const error = err instanceof Error ? err : new Error ( String ( err ) ) ;
254
263
logger . debug (
255
264
LogId . atlasConnectFailure ,
0 commit comments