Skip to content

Commit 2a52e2c

Browse files
chore: MCP-247 method to detect if a cluster support search indexes
1 parent c12de89 commit 2a52e2c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/session.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,20 @@ export class Session extends EventEmitter<SessionEvents> {
153153
get connectedAtlasCluster(): AtlasClusterConnectionInfo | undefined {
154154
return this.connectionManager.currentConnectionState.connectedAtlasCluster;
155155
}
156+
157+
async isSearchIndexSupported(): Promise<boolean> {
158+
try {
159+
const dummyDatabase = `db-${Date.now()}`;
160+
const dummyCollection = `coll-${Date.now()}`;
161+
// If a cluster supports search indexes, the call below will succeed
162+
// with a cursor otherwise will throw a MongoServerError
163+
await this.serviceProvider.getSearchIndexes(dummyDatabase, dummyCollection);
164+
return true;
165+
} catch (error) {
166+
if (error instanceof Error && "codeName" in error && error.codeName === "SearchNotEnabled") {
167+
return false;
168+
}
169+
throw error;
170+
}
171+
}
156172
}

0 commit comments

Comments
 (0)