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

mongodb-js / mongodb-mcp-server / 14637601756

24 Apr 2025 08:57AM UTC coverage: 42.737% (-32.7%) from 75.474%
14637601756

Pull #103

github

fmenezes
fix: rename describes
Pull Request #103: refactor: split test helpers

30 of 187 branches covered (16.04%)

Branch coverage included in aggregate %.

376 of 763 relevant lines covered (49.28%)

1.85 hits per line

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

70.0
/src/tools/mongodb/create/createIndex.ts
1
import { z } from "zod";
1✔
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
1✔
4
import { ToolArgs, OperationType } from "../../tool.js";
5
import { IndexDirection } from "mongodb";
6

7
export class CreateIndexTool extends MongoDBToolBase {
1✔
8
    protected name = "create-index";
2✔
9
    protected description = "Create an index for a collection";
2✔
10
    protected argsShape = {
2✔
11
        ...DbOperationArgs,
12
        keys: z.record(z.string(), z.custom<IndexDirection>()).describe("The index definition"),
13
        name: z.string().optional().describe("The name of the index"),
14
    };
15

16
    protected operationType: OperationType = "create";
2✔
17

18
    protected async execute({
19
        database,
20
        collection,
21
        keys,
22
        name,
23
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
24
        const provider = await this.ensureConnected();
×
25
        const indexes = await provider.createIndexes(database, collection, [
×
26
            {
27
                key: keys,
28
                name,
29
            },
30
        ]);
31

32
        return {
×
33
            content: [
34
                {
35
                    text: `Created the index "${indexes[0]}" on collection "${collection}" in database "${database}"`,
36
                    type: "text",
37
                },
38
            ],
39
        };
40
    }
41
}
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