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

mongodb-js / mongodb-mcp-server / 14614840974

23 Apr 2025 09:33AM UTC coverage: 76.675% (+23.5%) from 53.208%
14614840974

Pull #83

github

fmenezes
fix: styles
Pull Request #83: chore: add atlas tests

81 of 152 branches covered (53.29%)

Branch coverage included in aggregate %.

28 of 39 new or added lines in 6 files covered. (71.79%)

4 existing lines in 3 files now uncovered.

560 of 684 relevant lines covered (81.87%)

27.03 hits per line

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

61.54
/src/tools/mongodb/read/aggregate.ts
1
import { z } from "zod";
16✔
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
16✔
4
import { ToolArgs, OperationType } from "../../tool.js";
5

6
export const AggregateArgs = {
16✔
7
    pipeline: z.array(z.object({}).passthrough()).describe("An array of aggregation stages to execute"),
8
    limit: z.number().optional().default(10).describe("The maximum number of documents to return"),
9
};
10

11
export class AggregateTool extends MongoDBToolBase {
16✔
12
    protected name = "aggregate";
16✔
13
    protected description = "Run an aggregation against a MongoDB collection";
16✔
14
    protected argsShape = {
16✔
15
        ...DbOperationArgs,
16
        ...AggregateArgs,
17
    };
18
    protected operationType: OperationType = "read";
16✔
19

20
    protected async execute({
21
        database,
22
        collection,
23
        pipeline,
24
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
25
        const provider = await this.ensureConnected();
×
26
        const documents = await provider.aggregate(database, collection, pipeline).toArray();
×
27

28
        const content: Array<{ text: string; type: "text" }> = [
×
29
            {
30
                text: `Found ${documents.length} documents in the collection \`${collection}\`:`,
31
                type: "text",
32
            },
33
            ...documents.map((doc) => {
34
                return {
×
35
                    text: JSON.stringify(doc),
36
                    type: "text",
37
                } as { text: string; type: "text" };
38
            }),
39
        ];
40

41
        return {
×
42
            content,
43
        };
44
    }
45
}
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