@@ -32,9 +32,33 @@ export interface ConnectionState {
3232 connectedAtlasCluster ?: AtlasClusterConnectionInfo ;
3333}
3434
35- export interface ConnectionStateConnected extends ConnectionState {
36- tag : "connected" ;
37- serviceProvider : NodeDriverServiceProvider ;
35+ export class ConnectionStateConnected implements ConnectionState {
36+ public tag = "connected" as const ;
37+
38+ constructor (
39+ public serviceProvider : NodeDriverServiceProvider ,
40+ public connectionStringAuthType ?: ConnectionStringAuthType ,
41+ public connectedAtlasCluster ?: AtlasClusterConnectionInfo
42+ ) { }
43+
44+ private _isSearchSupported ?: boolean ;
45+
46+ public async isSearchSupported ( ) : Promise < boolean > {
47+ if ( this . _isSearchSupported === undefined ) {
48+ try {
49+ const dummyDatabase = `search-index-test-db-${ Date . now ( ) } ` ;
50+ const dummyCollection = `search-index-test-coll-${ Date . now ( ) } ` ;
51+ // If a cluster supports search indexes, the call below will succeed
52+ // with a cursor otherwise will throw an Error
53+ await this . serviceProvider . getSearchIndexes ( dummyDatabase , dummyCollection ) ;
54+ this . _isSearchSupported = true ;
55+ } catch {
56+ this . _isSearchSupported = false ;
57+ }
58+ }
59+
60+ return this . _isSearchSupported ;
61+ }
3862}
3963
4064export interface ConnectionStateConnecting extends ConnectionState {
@@ -199,12 +223,10 @@ export class MCPConnectionManager extends ConnectionManager {
199223 } ) ;
200224 }
201225
202- return this . changeState ( "connection-success" , {
203- tag : "connected" ,
204- connectedAtlasCluster : settings . atlas ,
205- serviceProvider : await serviceProvider ,
206- connectionStringAuthType,
207- } ) ;
226+ return this . changeState (
227+ "connection-success" ,
228+ new ConnectionStateConnected ( await serviceProvider , connectionStringAuthType , settings . atlas )
229+ ) ;
208230 } catch ( error : unknown ) {
209231 const errorReason = error instanceof Error ? error . message : `${ error as string } ` ;
210232 this . changeState ( "connection-error" , {
@@ -270,11 +292,14 @@ export class MCPConnectionManager extends ConnectionManager {
270292 this . currentConnectionState . tag === "connecting" &&
271293 this . currentConnectionState . connectionStringAuthType ?. startsWith ( "oidc" )
272294 ) {
273- this . changeState ( "connection-success" , {
274- ...this . currentConnectionState ,
275- tag : "connected" ,
276- serviceProvider : await this . currentConnectionState . serviceProvider ,
277- } ) ;
295+ this . changeState (
296+ "connection-success" ,
297+ new ConnectionStateConnected (
298+ await this . currentConnectionState . serviceProvider ,
299+ this . currentConnectionState . connectionStringAuthType ,
300+ this . currentConnectionState . connectedAtlasCluster
301+ )
302+ ) ;
278303 }
279304
280305 this . logger . info ( {
0 commit comments