• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 18284013540

06 Oct 2025 02:20PM UTC coverage: 82.488% (-0.02%) from 82.505%
18284013540

Pull #610

github

web-flow
Merge 042a4f2e6 into 071fc3bb8
Pull Request #610: feat(search): Add a new tool to list search and vector search indexes MCP-235

1107 of 1456 branches covered (76.03%)

Branch coverage included in aggregate %.

50 of 59 new or added lines in 2 files covered. (84.75%)

5346 of 6367 relevant lines covered (83.96%)

69.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.28
/src/tools/mongodb/search/listSearchIndexes.ts
1
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import type { ToolArgs, OperationType } from "../../tool.js";
3
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
2✔
4
import { formatUntrustedData } from "../../tool.js";
2✔
5

6
export type SearchIndexStatus = {
7
    name: string;
8
    type: string;
9
    status: string;
10
    queryable: boolean;
11
    latestDefinition: Document;
12
};
13

14
export class ListSearchIndexesTool extends MongoDBToolBase {
2✔
15
    public name = "list-search-indexes";
78✔
16
    protected description = "Describes the search and vector search indexes for a single collection";
78✔
17
    protected argsShape = DbOperationArgs;
78✔
18
    public operationType: OperationType = "metadata";
78✔
19

20
    protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
2✔
21
        const provider = await this.ensureConnected();
4✔
22
        const indexes = await provider.getSearchIndexes(database, collection);
4✔
23
        const trimmedIndexDefinitions = this.pickRelevantInformation(indexes);
3✔
24

25
        if (trimmedIndexDefinitions.length > 0) {
4✔
26
            return {
2✔
27
                content: formatUntrustedData(
2✔
28
                    `Found ${trimmedIndexDefinitions.length} search and vector search indexes in ${database}.${collection}`,
2✔
29
                    indexes.map((index) => JSON.stringify(index)).join("\n")
2✔
30
                ),
2✔
31
            };
2✔
32
        } else {
4✔
33
            return {
1✔
34
                content: formatUntrustedData(
1✔
35
                    `There are no search or vector search indexes in ${database}.${collection}`
1✔
36
                ),
1✔
37
            };
1✔
38
        }
1✔
39
    }
4✔
40

41
    /**
42
     * Atlas Search index status contains a lot of information that is not relevant for the agent at this stage.
43
     * Like for example, the status on each of the dedicated nodes. We only care about the main status, if it's
44
     * queryable and the index name. We are also picking the index definition as it can be used by the agent to
45
     * understand which fields are available for searching.
46
     **/
47
    protected pickRelevantInformation(indexes: Record<string, unknown>[]): SearchIndexStatus[] {
2✔
48
        return indexes.map((index) => ({
3✔
49
            name: (index["name"] ?? "default") as string,
2!
50
            type: (index["type"] ?? "UNKNOWN") as string,
2!
51
            status: (index["status"] ?? "UNKNOWN") as string,
2!
52
            queryable: (index["queryable"] ?? false) as boolean,
2!
53
            latestDefinition: index["latestDefinition"] as Document,
2✔
54
        }));
3✔
55
    }
3✔
56

57
    protected handleError(error: unknown): Promise<CallToolResult> | CallToolResult {
2✔
58
        if (error instanceof Error && "codeName" in error && error.codeName === "SearchNotEnabled") {
1✔
59
            return {
1✔
60
                content: [
1✔
61
                    {
1✔
62
                        text: "This MongoDB cluster does not support Search Indexes. Make sure you are using an Atlas Cluster, either remotely in Atlas or using the Atlas Local image, or your cluster supports MongoDB Search.",
1✔
63
                        type: "text",
1✔
64
                    },
1✔
65
                ],
1✔
66
            };
1✔
67
        } else {
1!
NEW
68
            return {
×
NEW
69
                content: [
×
NEW
70
                    {
×
NEW
71
                        text: "Collection does not exist",
×
NEW
72
                        type: "text",
×
NEW
73
                    },
×
NEW
74
                ],
×
NEW
75
            };
×
NEW
76
        }
×
77
    }
1✔
78
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc