Skip to content

Commit b8a85a3

Browse files
feat: listSearchIndexes now lists index status info (#258)
1 parent 298adf4 commit b8a85a3

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,26 @@ NOTE: atlas tools are only available when you set credentials on [configuration]
142142
- `insert-one` - Insert a single document into a MongoDB collection
143143
- `insert-many` - Insert multiple documents into a MongoDB collection
144144
- `create-index` - Create an index for a MongoDB collection
145+
- `create-search-index` - Create a search index for a MongoDB collection
146+
- `create-vector-index` - Create a vector search index for a MongoDB collection
145147
- `update-one` - Update a single document in a MongoDB collection
146148
- `update-many` - Update multiple documents in a MongoDB collection
149+
- `update-search-index` - Update a search index for a MongoDB collection
150+
- `update-vector-index` - Update a vector search index for a MongoDB collection
147151
- `rename-collection` - Rename a MongoDB collection
148152
- `delete-one` - Delete a single document from a MongoDB collection
149153
- `delete-many` - Delete multiple documents from a MongoDB collection
150154
- `drop-collection` - Remove a collection from a MongoDB database
151155
- `drop-database` - Remove a MongoDB database
156+
- `drop-search-index` - Remove a search or vector search index from a MongoDB collection
152157
- `list-databases` - List all databases for a MongoDB connection
153158
- `list-collections` - List all collections for a given database
154159
- `collection-indexes` - Describe the indexes for a collection
160+
- `collection-search-indexes` - Describe the search indexes for a collection
155161
- `collection-schema` - Describe the schema for a collection
156162
- `collection-storage-size` - Get the size of a collection in MB
157163
- `db-stats` - Return statistics about a MongoDB database
164+
- `run-pipeline` - Run an aggregation against JSON documents (Atlas account not required)
158165

159166
## Configuration
160167

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export interface IndexDefinitionVersion {
2+
version: number;
3+
createdAt: string; // ISO 8601 date string
4+
}
5+
6+
export interface IndexDefinition {
7+
[key: string]: unknown;
8+
}
9+
10+
export interface SynonymMappingStatusDetails {
11+
status: string;
12+
queryable: boolean;
13+
message?: string;
14+
}
15+
16+
export interface IndexStatusInfo {
17+
status: string;
18+
queryable: boolean;
19+
synonymMappingStatus?: string;
20+
synonymMappingStatusDetails?: SynonymMappingStatusDetails;
21+
definitionVersion: IndexDefinitionVersion;
22+
definition: IndexDefinition;
23+
}
24+
25+
export interface SearchIndexStatusDetail {
26+
hostname: string;
27+
status: string;
28+
queryable: boolean;
29+
mainIndex: IndexStatusInfo;
30+
stagedIndex?: IndexStatusInfo;
31+
}
32+
33+
export interface SynonymMappingStatusDetail {
34+
status: string;
35+
queryable: boolean;
36+
message?: string;
37+
}
38+
39+
export interface ListSearchIndexOutput {
40+
id: string;
41+
name: string;
42+
status: string;
43+
queryable: boolean;
44+
latestDefinitionVersion: IndexDefinitionVersion;
45+
latestDefinition: IndexDefinition;
46+
statusDetail: SearchIndexStatusDetail[];
47+
synonymMappingStatus?: "BUILDING" | "FAILED" | "READY";
48+
synonymMappingStatusDetail?: SynonymMappingStatusDetail[];
49+
}

src/tools/mongodb/read/collectionSearchIndexes.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { ToolArgs, OperationType } from "../../tool.js";
44
import { z } from "zod";
5+
import { ListSearchIndexOutput } from "../../../common/search/listSearchIndexesOutput.js";
56

67
export const ListSearchIndexesArgs = {
78
indexName: z
@@ -12,10 +13,6 @@ export const ListSearchIndexesArgs = {
1213
"The name of the index to return information about. Returns all indexes on collection if not provided."
1314
),
1415
};
15-
export interface SearchIndex {
16-
name: string;
17-
latestDefinition: Record<string, unknown>;
18-
}
1916

2017
export class CollectionSearchIndexesTool extends MongoDBToolBase {
2118
protected name = "collection-search-indexes";
@@ -33,12 +30,18 @@ export class CollectionSearchIndexesTool extends MongoDBToolBase {
3330
indexName,
3431
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
3532
const provider = await this.ensureConnected();
36-
37-
const indexes: SearchIndex[] = (
38-
(await provider.getSearchIndexes(database, collection, indexName)) as SearchIndex[]
33+
const indexes: ListSearchIndexOutput[] = (
34+
(await provider.getSearchIndexes(database, collection, indexName)) as ListSearchIndexOutput[]
3935
).map((doc) => ({
36+
id: doc.id,
4037
name: doc.name,
38+
status: doc.status,
39+
queryable: doc.queryable,
40+
latestDefinitionVersion: doc.latestDefinitionVersion,
4141
latestDefinition: doc.latestDefinition,
42+
statusDetail: doc.statusDetail,
43+
synonymMappingStatus: doc.synonymMappingStatus,
44+
synonymMappingStatusDetail: doc.synonymMappingStatusDetail,
4245
}));
4346

4447
return {
@@ -51,7 +54,17 @@ export class CollectionSearchIndexesTool extends MongoDBToolBase {
5154
},
5255
...(indexes.map((indexDefinition) => {
5356
return {
54-
text: `\nName: "${indexDefinition.name}"\nDefinition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}\n`,
57+
text: [
58+
`Name: "${indexDefinition.name}"`,
59+
`Definition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}`,
60+
`Queryable: ${indexDefinition.queryable}`,
61+
`Status: "${indexDefinition.status}"`,
62+
`Status Detail: ${JSON.stringify(indexDefinition.statusDetail, null, 2)}`,
63+
`Definition Version: ${JSON.stringify(indexDefinition.latestDefinitionVersion, null, 2)}`,
64+
`Synonym Mapping Status: ${indexDefinition.synonymMappingStatus}`,
65+
`Synonym Mapping Status Detail: ${JSON.stringify(indexDefinition.synonymMappingStatusDetail, null, 2)}`,
66+
`ID: ${indexDefinition.id}`,
67+
].join("\n"),
5568
type: "text",
5669
};
5770
}) as { text: string; type: "text" }[]),

0 commit comments

Comments
 (0)