Skip to content
Next Next commit
chore: MCP-247 method to detect if a cluster support search indexes
  • Loading branch information
himanshusinghs committed Oct 13, 2025
commit 86d509d6c14787d7abbe78fb8709960b5c1f7d07
16 changes: 16 additions & 0 deletions src/common/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,20 @@ export class Session extends EventEmitter<SessionEvents> {
get connectedAtlasCluster(): AtlasClusterConnectionInfo | undefined {
return this.connectionManager.currentConnectionState.connectedAtlasCluster;
}

async isSearchIndexSupported(): Promise<boolean> {
try {
const dummyDatabase = `db-${Date.now()}`;
const dummyCollection = `coll-${Date.now()}`;
// If a cluster supports search indexes, the call below will succeed
// with a cursor otherwise will throw a MongoServerError
await this.serviceProvider.getSearchIndexes(dummyDatabase, dummyCollection);
return true;
} catch (error) {
if (error instanceof Error && "codeName" in error && error.codeName === "SearchNotEnabled") {
return false;
}
throw error;
}
}
}