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

mongodb-js / mongodb-mcp-server / 16275099623

14 Jul 2025 06:42PM UTC coverage: 77.524% (+2.3%) from 75.27%
16275099623

Pull #363

github

web-flow
Merge 3f10cbde7 into 184841400
Pull Request #363: chore(tests): switch to vitest

499 of 688 branches covered (72.53%)

Branch coverage included in aggregate %.

0 of 26 new or added lines in 2 files covered. (0.0%)

291 existing lines in 26 files now uncovered.

2833 of 3610 relevant lines covered (78.48%)

28.87 hits per line

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

95.65
/src/tools/mongodb/metadata/collectionStorageSize.ts
1
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
2✔
3
import { ToolArgs, OperationType } from "../../tool.js";
4

5
export class CollectionStorageSizeTool extends MongoDBToolBase {
2✔
6
    public name = "collection-storage-size";
34✔
7
    protected description = "Gets the size of the collection";
34✔
8
    protected argsShape = DbOperationArgs;
34✔
9

10
    public operationType: OperationType = "metadata";
34✔
11

12
    protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
2✔
13
        const provider = await this.ensureConnected();
6✔
14
        const [{ value }] = (await provider
5✔
15
            .aggregate(database, collection, [
5✔
16
                { $collStats: { storageStats: {} } },
5✔
17
                { $group: { _id: null, value: { $sum: "$storageStats.size" } } },
5✔
18
            ])
5✔
19
            .toArray()) as [{ value: number }];
5✔
20

21
        const { units, value: scaledValue } = CollectionStorageSizeTool.getStats(value);
3✔
22

23
        return {
3✔
24
            content: [
3✔
25
                {
3✔
26
                    text: `The size of "${database}.${collection}" is \`${scaledValue.toFixed(2)} ${units}\``,
3✔
27
                    type: "text",
3✔
28
                },
3✔
29
            ],
3✔
30
        };
3✔
31
    }
6✔
32

33
    protected handleError(
2✔
34
        error: unknown,
3✔
35
        args: ToolArgs<typeof this.argsShape>
3✔
36
    ): Promise<CallToolResult> | CallToolResult {
3✔
37
        if (error instanceof Error && "codeName" in error && error.codeName === "NamespaceNotFound") {
3✔
38
            return {
2✔
39
                content: [
2✔
40
                    {
2✔
41
                        text: `The size of "${args.database}.${args.collection}" cannot be determined because the collection does not exist.`,
2✔
42
                        type: "text",
2✔
43
                    },
2✔
44
                ],
2✔
45
            };
2✔
46
        }
2✔
47

48
        return super.handleError(error, args);
1✔
49
    }
3✔
50

51
    private static getStats(value: number): { value: number; units: string } {
2✔
52
        const kb = 1024;
3✔
53
        const mb = kb * 1024;
3✔
54
        const gb = mb * 1024;
3✔
55

56
        if (value > gb) {
3!
57
            return { value: value / gb, units: "GB" };
×
UNCOV
58
        }
×
59

60
        if (value > mb) {
3✔
61
            return { value: value / mb, units: "MB" };
1✔
62
        }
1✔
63
        if (value > kb) {
3✔
64
            return { value: value / kb, units: "KB" };
1✔
65
        }
1✔
66
        return { value, units: "bytes" };
1✔
67
    }
3✔
68
}
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