Skip to content

Commit 1164b91

Browse files
committed
chore: load the systemCA and check for FIPS, help and version
For help we are refering to the README.md, if we want something more fancy we porobably want to have better documentation generation so we don't maintain two files (here and the README.md)
1 parent 26992ca commit 1164b91

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

src/common/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const OPTIONS = {
6666
"tlsAllowInvalidCertificates",
6767
"tlsAllowInvalidHostnames",
6868
"tlsFIPSMode",
69-
"tlsUseSystemCA",
7069
"version",
7170
],
7271
array: ["disabledTools", "loggers"],

src/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
import { ConsoleLogger, LogId } from "./common/logger.js";
44
import { config } from "./common/config.js";
5+
import crypto from "crypto";
6+
import { packageInfo } from "./common/packageInfo.js";
57
import { StdioRunner } from "./transports/stdio.js";
68
import { StreamableHttpRunner } from "./transports/streamableHttp.js";
9+
import { systemCA } from "@mongodb-js/devtools-proxy-support";
710

811
async function main(): Promise<void> {
12+
systemCA().catch(() => undefined); // load system CA asynchronously as in mongosh
13+
14+
assertFIPSMode();
15+
assertHelpMode();
16+
assertVersionMode();
17+
918
const transportRunner = config.transport === "stdio" ? new StdioRunner(config) : new StreamableHttpRunner(config);
1019

1120
const shutdown = (): void => {
@@ -78,3 +87,40 @@ main().catch((error: unknown) => {
7887
});
7988
process.exit(1);
8089
});
90+
91+
function assertFIPSMode() {
92+
let fipsError: Error | undefined = undefined;
93+
if (config.tlsFIPSMode) {
94+
if (!fipsError && !crypto.getFips()) {
95+
fipsError = new Error("FIPS mode not enabled despite requested.");
96+
}
97+
}
98+
99+
if (fipsError) {
100+
if (process.config.variables.node_shared_openssl) {
101+
console.error(
102+
"Could not enable FIPS mode. Please ensure that your system OpenSSL installation supports FIPS."
103+
);
104+
} else {
105+
console.error("Could not enable FIPS mode. This installation does not appear to support FIPS.");
106+
}
107+
console.error("Error details:");
108+
console.error(fipsError);
109+
process.exit(1);
110+
}
111+
}
112+
113+
function assertHelpMode() {
114+
if (!!config.help) {
115+
console.log("For usage information refer to the README.md:");
116+
console.log("https://github.com/mongodb-js/mongodb-mcp-server?tab=readme-ov-file#quick-start");
117+
process.exit(0);
118+
}
119+
}
120+
121+
function assertVersionMode() {
122+
if (!!config.version) {
123+
console.log(packageInfo.version);
124+
process.exit(0);
125+
}
126+
}

tests/unit/common/config.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from "vitest";
22
import { setupUserConfig, UserConfig } from "../../../src/common/config.js";
33

4-
describe.only("config", () => {
4+
describe("config", () => {
55
describe("env var parsing", () => {
66
describe("string cases", () => {
77
const testCases = {
@@ -227,7 +227,7 @@ describe.only("config", () => {
227227
});
228228

229229
for (const [key, value] of Object.entries(expected)) {
230-
expect(actual[key as keyof UserConfig]).toBe(value as unknown);
230+
expect(actual[key as keyof UserConfig]).toBe(value);
231231
}
232232
});
233233
}
@@ -311,10 +311,6 @@ describe.only("config", () => {
311311
cli: ["--tlsFIPSMode"],
312312
expected: { tlsFIPSMode: true },
313313
},
314-
{
315-
cli: ["--tlsUseSystemCA"],
316-
expected: { tlsUseSystemCA: true },
317-
},
318314
{
319315
cli: ["--version"],
320316
expected: { version: true },
@@ -330,7 +326,7 @@ describe.only("config", () => {
330326
});
331327

332328
for (const [key, value] of Object.entries(expected)) {
333-
expect(actual[key as keyof UserConfig]).toBe(value as unknown);
329+
expect(actual[key as keyof UserConfig]).toBe(value);
334330
}
335331
});
336332
}
@@ -357,7 +353,7 @@ describe.only("config", () => {
357353
});
358354

359355
for (const [key, value] of Object.entries(expected)) {
360-
expect(actual[key as keyof UserConfig]).toEqual(value as unknown);
356+
expect(actual[key as keyof UserConfig]).toEqual(value);
361357
}
362358
});
363359
}

0 commit comments

Comments
 (0)