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

mongodb-js / mongodb-mcp-server / 17214463920

25 Aug 2025 04:18PM UTC coverage: 81.821%. First build
17214463920

Pull #475

github

web-flow
Merge 1e376c2b8 into 46a93cca5
Pull Request #475: chore: add more information when there is a failure connecting MCP-92

908 of 1137 branches covered (79.86%)

Branch coverage included in aggregate %.

24 of 25 new or added lines in 3 files covered. (96.0%)

4367 of 5310 relevant lines covered (82.24%)

143.51 hits per line

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

96.25
/src/resources/common/debug.ts
1
import { ReactiveResource } from "../resource.js";
4✔
2
import type { Telemetry } from "../../telemetry/telemetry.js";
3
import type { Session, UserConfig } from "../../lib.js";
4
import type { AtlasClusterConnectionInfo, ConnectionStateErrored } from "../../common/connectionManager.js";
5

6
type ConnectionStateDebuggingInformation = {
7
    readonly tag: "connected" | "connecting" | "disconnected" | "errored";
8
    readonly connectionStringAuthType?: "scram" | "ldap" | "kerberos" | "oidc-auth-flow" | "oidc-device-flow" | "x.509";
9
    readonly errorReason?: string;
10
    readonly connectedAtlasCluster?: AtlasClusterConnectionInfo;
11
};
12

13
export class DebugResource extends ReactiveResource<
4✔
14
    ConnectionStateDebuggingInformation,
15
    readonly ["connect", "disconnect", "close", "connection-error"]
16
> {
4✔
17
    constructor(session: Session, config: UserConfig, telemetry: Telemetry) {
4✔
18
        super({
188✔
19
            resourceConfiguration: {
188✔
20
                name: "debug-mongodb",
188✔
21
                uri: "debug://mongodb",
188✔
22
                config: {
188✔
23
                    description:
188✔
24
                        "Debugging information for MongoDB connectivity issues. Tracks the last connectivity attempt and error information.",
188✔
25
                },
188✔
26
            },
188✔
27
            options: {
188✔
28
                initial: { tag: "disconnected" },
188✔
29
                events: ["connect", "disconnect", "close", "connection-error"],
188✔
30
            },
188✔
31
            session,
188✔
32
            config,
188✔
33
            telemetry,
188✔
34
        });
188✔
35
    }
188✔
36
    reduce(
4✔
37
        eventName: "connect" | "disconnect" | "close" | "connection-error",
1,926✔
38
        event: ConnectionStateErrored | undefined
1,926✔
39
    ): ConnectionStateDebuggingInformation {
1,926✔
40
        switch (eventName) {
1,926✔
41
            case "connect":
1,926✔
42
                return { tag: "connected" };
796✔
43
            case "connection-error": {
1,926✔
44
                return {
86✔
45
                    tag: "errored",
86✔
46
                    connectionStringAuthType: event?.connectionStringAuthType,
86✔
47
                    connectedAtlasCluster: event?.connectedAtlasCluster,
86✔
48
                    errorReason:
86✔
49
                        event?.errorReason ??
86!
NEW
50
                        "Could not find a reason. This might be a bug in the MCP Server. Please open an issue in https://github.com/mongodb-js/mongodb-mcp-server.",
×
51
                };
86✔
52
            }
86✔
53
            case "disconnect":
1,926✔
54
            case "close":
1,926✔
55
                return { tag: "disconnected" };
1,044✔
56
        }
1,926✔
57
    }
1,926✔
58

59
    toOutput(): string {
4✔
60
        let result = "";
24✔
61

62
        switch (this.current.tag) {
24✔
63
            case "connected":
24✔
64
                result += "The user is connected to the MongoDB cluster.";
4✔
65
                break;
4✔
66
            case "errored":
24✔
67
                result += `The user is not connected to a MongoDB cluster because of an error.\n`;
12✔
68
                if (this.current.connectedAtlasCluster) {
12✔
69
                    result += `Attempted connecting to Atlas Cluster "${this.current.connectedAtlasCluster.clusterName}" in project with id "${this.current.connectedAtlasCluster.projectId}".\n`;
4✔
70
                }
4✔
71

72
                result += `The inferred authentication mechanism is "${this.current.connectionStringAuthType ?? "could-not-infer"}".\n`;
12✔
73
                result += `<error>${this.current.errorReason}</error>`;
12✔
74
                break;
12✔
75
            case "connecting":
24!
76
            case "disconnected":
24✔
77
                result += "The user is not connected to a MongoDB cluster.";
8✔
78
                break;
8✔
79
        }
24✔
80

81
        return result;
24✔
82
    }
24✔
83
}
4✔
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