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

mongodb-js / mongodb-mcp-server / 17429932259

03 Sep 2025 09:59AM UTC coverage: 81.125% (+0.2%) from 80.965%
17429932259

Pull #502

github

web-flow
Merge ed6adc6d6 into 47c0a09e0
Pull Request #502: chore: extend library interfaces to allow injecting a custom connection error handler MCP-132

901 of 1199 branches covered (75.15%)

Branch coverage included in aggregate %.

92 of 106 new or added lines in 9 files covered. (86.79%)

2 existing lines in 2 files now uncovered.

4579 of 5556 relevant lines covered (82.42%)

44.39 hits per line

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

0.79
/src/index.ts
1
#!/usr/bin/env node
2✔
2

3
function enableFipsIfRequested(): void {
×
4
    let fipsError: Error | undefined;
×
5
    const tlsFIPSMode = process.argv.includes("--tlsFIPSMode");
×
6

7
    if (tlsFIPSMode) {
×
8
        try {
×
9
            // eslint-disable-next-line
10
            require("crypto").setFips(1);
×
11
        } catch (err: unknown) {
×
12
            fipsError ??= err as Error;
×
13
        }
×
14
    }
×
15

16
    if (tlsFIPSMode) {
×
17
        if (!fipsError && !crypto.getFips()) {
×
18
            fipsError = new Error("FIPS mode not enabled despite requested due to unknown error.");
×
19
        }
×
20
    }
×
21

22
    if (fipsError) {
×
23
        if (process.config.variables.node_shared_openssl) {
×
24
            console.error(
×
25
                "Could not enable FIPS mode. Please ensure that your system OpenSSL installation supports FIPS."
×
26
            );
×
27
        } else {
×
28
            console.error("Could not enable FIPS mode. This installation does not appear to support FIPS.");
×
29
        }
×
30
        console.error("Error details:");
×
31
        console.error(fipsError);
×
32
        process.exit(1);
×
33
    }
×
34
}
×
35

36
enableFipsIfRequested();
×
37

38
import { ConsoleLogger, LogId } from "./common/logger.js";
×
39
import { config } from "./common/config.js";
×
40
import crypto from "crypto";
×
41
import { packageInfo } from "./common/packageInfo.js";
×
42
import { StdioRunner } from "./transports/stdio.js";
×
43
import { StreamableHttpRunner } from "./transports/streamableHttp.js";
×
44
import { systemCA } from "@mongodb-js/devtools-proxy-support";
×
45

46
async function main(): Promise<void> {
×
47
    systemCA().catch(() => undefined); // load system CA asynchronously as in mongosh
×
48

49
    assertHelpMode();
×
50
    assertVersionMode();
×
51

NEW
52
    const transportRunner =
×
NEW
53
        config.transport === "stdio"
×
NEW
54
            ? new StdioRunner({
×
NEW
55
                  userConfig: config,
×
NEW
56
              })
×
NEW
57
            : new StreamableHttpRunner({
×
NEW
58
                  userConfig: config,
×
NEW
59
              });
×
60
    const shutdown = (): void => {
×
61
        transportRunner.logger.info({
×
62
            id: LogId.serverCloseRequested,
×
63
            context: "server",
×
64
            message: `Server close requested`,
×
65
        });
×
66

67
        transportRunner
×
68
            .close()
×
69
            .then(() => {
×
70
                transportRunner.logger.info({
×
71
                    id: LogId.serverClosed,
×
72
                    context: "server",
×
73
                    message: `Server closed`,
×
74
                });
×
75
                process.exit(0);
×
76
            })
×
77
            .catch((error: unknown) => {
×
78
                transportRunner.logger.error({
×
79
                    id: LogId.serverCloseFailure,
×
80
                    context: "server",
×
81
                    message: `Error closing server: ${error as string}`,
×
82
                });
×
83
                process.exit(1);
×
84
            });
×
85
    };
×
86

87
    process.on("SIGINT", shutdown);
×
88
    process.on("SIGABRT", shutdown);
×
89
    process.on("SIGTERM", shutdown);
×
90
    process.on("SIGQUIT", shutdown);
×
91

92
    try {
×
93
        await transportRunner.start();
×
94
    } catch (error: unknown) {
×
95
        transportRunner.logger.info({
×
96
            id: LogId.serverCloseRequested,
×
97
            context: "server",
×
98
            message: `Closing server due to error: ${error as string}`,
×
99
            noRedaction: true,
×
100
        });
×
101

102
        try {
×
103
            await transportRunner.close();
×
104
            transportRunner.logger.info({
×
105
                id: LogId.serverClosed,
×
106
                context: "server",
×
107
                message: "Server closed",
×
108
            });
×
109
        } catch (error: unknown) {
×
110
            transportRunner.logger.error({
×
111
                id: LogId.serverCloseFailure,
×
112
                context: "server",
×
113
                message: `Error closing server: ${error as string}`,
×
114
            });
×
115
        }
×
116
        throw error;
×
117
    }
×
118
}
×
119

120
main().catch((error: unknown) => {
×
121
    // At this point, we may be in a very broken state, so we can't rely on the logger
122
    // being functional. Instead, create a brand new ConsoleLogger and log the error
123
    // to the console.
124
    const logger = new ConsoleLogger();
×
125
    logger.emergency({
×
126
        id: LogId.serverStartFailure,
×
127
        context: "server",
×
128
        message: `Fatal error running server: ${error as string}`,
×
129
    });
×
130
    process.exit(1);
×
131
});
×
132

133
function assertHelpMode(): void | never {
×
134
    if (config.help) {
×
135
        console.log("For usage information refer to the README.md:");
×
136
        console.log("https://github.com/mongodb-js/mongodb-mcp-server?tab=readme-ov-file#quick-start");
×
137
        process.exit(0);
×
138
    }
×
139
}
×
140

141
function assertVersionMode(): void | never {
×
142
    if (config.version) {
×
143
        console.log(packageInfo.version);
×
144
        process.exit(0);
×
145
    }
×
146
}
×
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