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

mongodb-js / mongodb-mcp-server / 14705884283

28 Apr 2025 10:45AM UTC coverage: 82.547% (+0.9%) from 81.696%
14705884283

Pull #131

github

fmenezes
fix: make ip changes smooth
Pull Request #131: feat: add atlas-connect-cluster tool

147 of 229 branches covered (64.19%)

Branch coverage included in aggregate %.

26 of 31 new or added lines in 4 files covered. (83.87%)

60 existing lines in 8 files now uncovered.

780 of 894 relevant lines covered (87.25%)

49.5 hits per line

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

85.19
/src/tools/mongodb/mongodbTool.ts
1
import { z } from "zod";
31✔
2
import { ToolArgs, ToolBase, ToolCategory } from "../tool.js";
31✔
3
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
4
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
import { ErrorCodes, MongoDBError } from "../../errors.js";
31✔
6

31✔
7
export const DbOperationArgs = {
8
    database: z.string().describe("Database name"),
31✔
9
    collection: z.string().describe("Collection name"),
10
};
11

12
export abstract class MongoDBToolBase extends ToolBase {
13
    protected category: ToolCategory = "mongodb";
31✔
14

580✔
15
    protected async ensureConnected(): Promise<NodeDriverServiceProvider> {
16
        if (!this.session.serviceProvider && this.config.connectionString) {
17
            await this.connectToMongoDB(this.config.connectionString);
126✔
18
        }
19✔
19

19✔
20
        if (!this.session.serviceProvider) {
UNCOV
21
            throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, "Not connected to MongoDB");
×
22
        }
23

24
        return this.session.serviceProvider;
25
    }
UNCOV
26

×
27
    protected handleError(
28
        error: unknown,
29
        args: ToolArgs<typeof this.argsShape>
30
    ): Promise<CallToolResult> | CallToolResult {
126✔
31
        if (error instanceof MongoDBError && error.code === ErrorCodes.NotConnectedToMongoDB) {
19✔
32
            return {
33
                content: [
34
                    {
107✔
35
                        type: "text",
36
                        text: "You need to connect to a MongoDB instance before you can access its data.",
37
                    },
38
                    {
39
                        type: "text",
40
                        text: "Please use the 'connect' tool to connect to a MongoDB instance.",
41
                    },
23✔
42
                ],
19!
43
                isError: true,
44
            };
19✔
45
        }
46

47
        return super.handleError(error, args);
48
    }
49
}
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