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

mongodb-js / mongodb-mcp-server / 17159941478

22 Aug 2025 03:54PM UTC coverage: 81.682% (-0.3%) from 82.022%
17159941478

Pull #465

github

web-flow
Merge 9874379ed into 99a9b6a04
Pull Request #465: fix: wrap more tool responses in untrusted-user-data tags

852 of 1073 branches covered (79.4%)

Branch coverage included in aggregate %.

98 of 119 new or added lines in 17 files covered. (82.35%)

12 existing lines in 6 files now uncovered.

4343 of 5287 relevant lines covered (82.14%)

70.39 hits per line

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

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

6
export class CollectionIndexesTool extends MongoDBToolBase {
2✔
7
    public name = "collection-indexes";
80✔
8
    protected description = "Describe the indexes for a collection";
80✔
9
    protected argsShape = DbOperationArgs;
80✔
10
    public operationType: OperationType = "read";
80✔
11

12
    protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
2✔
13
        const provider = await this.ensureConnected();
10✔
14
        const indexes = await provider.getIndexes(database, collection);
8✔
15

16
        return {
4✔
17
            content: formatUntrustedData(
4✔
18
                `Found ${indexes.length} indexes in the collection "${collection}":`,
4✔
19
                indexes.length > 0
4✔
20
                    ? indexes
4✔
21
                          .map((index) => `Name: "${index.name}", definition: ${JSON.stringify(index.key)}`)
4✔
22
                          .join("\n")
4!
NEW
23
                    : undefined
×
24
            ),
10✔
25
        };
10✔
26
    }
10✔
27

28
    protected handleError(
2✔
29
        error: unknown,
6✔
30
        args: ToolArgs<typeof this.argsShape>
6✔
31
    ): Promise<CallToolResult> | CallToolResult {
6✔
32
        if (error instanceof Error && "codeName" in error && error.codeName === "NamespaceNotFound") {
6✔
33
            return {
4✔
34
                content: [
4✔
35
                    {
4✔
36
                        text: `The indexes for "${args.database}.${args.collection}" cannot be determined because the collection does not exist.`,
4✔
37
                        type: "text",
4✔
38
                    },
4✔
39
                ],
4✔
40
            };
4✔
41
        }
4✔
42

43
        return super.handleError(error, args);
2✔
44
    }
6✔
45
}
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