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

mongodb-js / mongodb-mcp-server / 19928292758

04 Dec 2025 12:03PM UTC coverage: 80.172% (-0.4%) from 80.581%
19928292758

Pull #777

github

web-flow
Merge 305c35330 into 18ff7cc01
Pull Request #777: chore: adopt strict validation for all command line arguments MCP-298

1451 of 1892 branches covered (76.69%)

Branch coverage included in aggregate %.

82 of 121 new or added lines in 8 files covered. (67.77%)

18 existing lines in 2 files now uncovered.

6640 of 8200 relevant lines covered (80.98%)

79.9 hits per line

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

0.6
/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";
×
39
import { ConsoleLogger, LogId } from "./common/logger.js";
×
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
import { DryRunModeRunner } from "./transports/dryModeRunner.js";
×
48

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

NEW
52
    const {
×
NEW
53
        error,
×
NEW
54
        warnings,
×
NEW
55
        parsed: config,
×
NEW
56
    } = createUserConfig({
×
NEW
57
        args: process.argv.slice(2),
×
NEW
58
    });
×
59

NEW
60
    if (!config || (error && error.length)) {
×
NEW
61
        console.error(`${error}
×
NEW
62
- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.`);
×
NEW
63
        process.exit(1);
×
NEW
64
    }
×
65

NEW
66
    if (warnings && warnings.length) {
×
NEW
67
        console.warn(`${warnings.join("\n")}
×
NEW
68
- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.`);
×
NEW
69
    }
×
70

71
    if (config.help) {
×
72
        handleHelpRequest();
×
73
    }
×
74

75
    if (config.version) {
×
76
        handleVersionRequest();
×
77
    }
×
78

79
    if (config.dryRun) {
×
80
        await handleDryRunRequest(config);
×
81
    }
×
82

83
    const transportRunner =
×
84
        config.transport === "stdio"
×
85
            ? new StdioRunner({
×
86
                  userConfig: config,
×
87
              })
×
88
            : new StreamableHttpRunner({
×
89
                  userConfig: config,
×
90
              });
×
91
    const shutdown = (): void => {
×
92
        transportRunner.logger.info({
×
93
            id: LogId.serverCloseRequested,
×
94
            context: "server",
×
95
            message: `Server close requested`,
×
96
        });
×
97

98
        transportRunner
×
99
            .close()
×
100
            .then(() => {
×
101
                transportRunner.logger.info({
×
102
                    id: LogId.serverClosed,
×
103
                    context: "server",
×
104
                    message: `Server closed`,
×
105
                });
×
106
                process.exit(0);
×
107
            })
×
108
            .catch((error: unknown) => {
×
109
                transportRunner.logger.error({
×
110
                    id: LogId.serverCloseFailure,
×
111
                    context: "server",
×
112
                    message: `Error closing server: ${error as string}`,
×
113
                });
×
114
                process.exit(1);
×
115
            });
×
116
    };
×
117

118
    process.on("SIGINT", shutdown);
×
119
    process.on("SIGABRT", shutdown);
×
120
    process.on("SIGTERM", shutdown);
×
121
    process.on("SIGQUIT", shutdown);
×
122

123
    try {
×
124
        await transportRunner.start();
×
125
    } catch (error: unknown) {
×
126
        transportRunner.logger.info({
×
127
            id: LogId.serverCloseRequested,
×
128
            context: "server",
×
129
            message: `Closing server due to error: ${error as string}`,
×
130
            noRedaction: true,
×
131
        });
×
132

133
        try {
×
134
            await transportRunner.close();
×
135
            transportRunner.logger.info({
×
136
                id: LogId.serverClosed,
×
137
                context: "server",
×
138
                message: "Server closed",
×
139
            });
×
140
        } catch (error: unknown) {
×
141
            transportRunner.logger.error({
×
142
                id: LogId.serverCloseFailure,
×
143
                context: "server",
×
144
                message: `Error closing server: ${error as string}`,
×
145
            });
×
146
        }
×
147
        throw error;
×
148
    }
×
149
}
×
150

151
main().catch((error: unknown) => {
×
152
    // At this point, we may be in a very broken state, so we can't rely on the logger
153
    // being functional. Instead, create a brand new ConsoleLogger and log the error
154
    // to the console.
155
    const logger = new ConsoleLogger(Keychain.root);
×
156
    logger.emergency({
×
157
        id: LogId.serverStartFailure,
×
158
        context: "server",
×
159
        message: `Fatal error running server: ${error as string}`,
×
160
    });
×
161
    process.exit(1);
×
162
});
×
163

164
function handleHelpRequest(): never {
×
165
    console.log("For usage information refer to the README.md:");
×
166
    console.log("https://github.com/mongodb-js/mongodb-mcp-server?tab=readme-ov-file#quick-start");
×
167
    process.exit(0);
×
168
}
×
169

170
function handleVersionRequest(): never {
×
171
    console.log(packageInfo.version);
×
172
    process.exit(0);
×
173
}
×
174

175
export async function handleDryRunRequest(config: UserConfig): Promise<never> {
×
176
    try {
×
177
        const runner = new DryRunModeRunner({
×
178
            userConfig: config,
×
179
            logger: {
×
180
                log(message): void {
×
181
                    console.log(message);
×
182
                },
×
183
                error(message): void {
×
184
                    console.error(message);
×
185
                },
×
186
            },
×
187
        });
×
188
        await runner.start();
×
189
        await runner.close();
×
190
        process.exit(0);
×
191
    } catch (error) {
×
192
        console.error(`Fatal error running server in dry run mode: ${error as string}`);
×
193
        process.exit(1);
×
194
    }
×
195
}
×
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