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

mongodb-js / mongodb-mcp-server / 19462524052

18 Nov 2025 10:20AM UTC coverage: 80.328% (+0.1%) from 80.187%
19462524052

Pull #729

github

web-flow
Merge 8e32474a4 into 53143eecd
Pull Request #729: chore: refactor config initialisation for CLI to allow easy extension from other config sources as well MCP-288

1328 of 1750 branches covered (75.89%)

Branch coverage included in aggregate %.

332 of 346 new or added lines in 12 files covered. (95.95%)

15 existing lines in 2 files now uncovered.

6406 of 7878 relevant lines covered (81.32%)

72.35 hits per line

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

0.78
/src/index.ts
1
#!/usr/bin/env node
3✔
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 crypto from "crypto";
×
NEW
39
import { ConsoleLogger, LogId } from "./common/logger.js";
×
NEW
40
import { createUserConfig } from "./common/config/createUserConfig.js";
×
41
import { type UserConfig } from "./common/config/userConfig.js";
42
import { packageInfo } from "./common/packageInfo.js";
×
43
import { StdioRunner } from "./transports/stdio.js";
×
44
import { StreamableHttpRunner } from "./transports/streamableHttp.js";
×
45
import { systemCA } from "@mongodb-js/devtools-proxy-support";
×
46
import { Keychain } from "./common/keychain.js";
×
47

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

NEW
51
    const config = createUserConfig();
×
NEW
52
    assertHelpMode(config);
×
NEW
53
    assertVersionMode(config);
×
54

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

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

90
    process.on("SIGINT", shutdown);
×
91
    process.on("SIGABRT", shutdown);
×
92
    process.on("SIGTERM", shutdown);
×
93
    process.on("SIGQUIT", shutdown);
×
94

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

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

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

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

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