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

mongodb-js / mongodb-mcp-server / 19641075675

24 Nov 2025 04:12PM UTC coverage: 80.33% (+0.2%) from 80.116%
19641075675

Pull #749

github

web-flow
Merge aa9c57feb into e4d3d7bc6
Pull Request #749: chore: split connect and switch-connection tool MCP-301

1344 of 1772 branches covered (75.85%)

Branch coverage included in aggregate %.

79 of 94 new or added lines in 6 files covered. (84.04%)

1 existing line in 1 file now uncovered.

6403 of 7872 relevant lines covered (81.34%)

68.12 hits per line

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

92.68
/src/tools/mongodb/connect/connect.ts
1
import { z } from "zod";
3✔
2
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { MongoDBToolBase } from "../mongodbTool.js";
3✔
4
import type { ToolArgs, OperationType, ToolConstructorParams } from "../../tool.js";
5
import type { Server } from "../../../server.js";
6
export class ConnectTool extends MongoDBToolBase {
3✔
7
    public override name = "connect";
3✔
8
    protected override description =
3✔
9
        "Connect to a MongoDB instance. The config resource captures if the server is already connected to a MongoDB cluster. If the user has configured a connection string or has previously called the connect tool, a connection is already established and there's no need to call this tool unless the user has explicitly requested to switch to a new MongoDB cluster.";
3✔
10

11
    // Here the default is empty just to trigger registration, but we're going to override it with the correct
12
    // schema in the register method.
13
    protected override argsShape = {
3✔
14
        connectionString: z.string().describe("MongoDB connection string (in the mongodb:// or mongodb+srv:// format)"),
3✔
15
    };
3✔
16

17
    public override operationType: OperationType = "connect";
3✔
18

19
    constructor({ session, config, telemetry, elicitation }: ToolConstructorParams) {
3✔
20
        super({ session, config, telemetry, elicitation });
105✔
21
        session.on("connect", () => {
105✔
22
            this.disable();
289✔
23
        });
105✔
24

25
        session.on("disconnect", () => {
105✔
26
            this.enable();
307✔
27
        });
105✔
28
    }
105✔
29

30
    public override register(server: Server): boolean {
3✔
31
        const registrationSuccessful = super.register(server);
105✔
32
        /**
33
         * When connected to mongodb we want to swap connect with
34
         * switch-connection tool.
35
         */
36
        if (registrationSuccessful && this.session.isConnectedToMongoDB) {
105!
NEW
37
            this.disable();
×
UNCOV
38
        }
×
39
        return registrationSuccessful;
105✔
40
    }
105✔
41

42
    protected override async execute({ connectionString }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
3✔
43
        await this.session.connectToMongoDB({ connectionString });
221✔
44

45
        return {
220✔
46
            content: [{ type: "text", text: "Successfully connected to MongoDB." }],
220✔
47
        };
220✔
48
    }
221✔
49
}
3✔
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