Skip to content

Commit 34a7296

Browse files
committed
chore: support for multiple hosts urls #327
1 parent 7639945 commit 34a7296

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/common/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ function parseEnvConfig(env: Record<string, unknown>): Partial<UserConfig> {
191191
return;
192192
}
193193
if (path.length === 0) {
194+
// MongoDB URLs must not be preprocessed
195+
if (value.startsWith("mongodb://") || value.startsWith("mongodb+srv://")) {
196+
obj[currentField] = value;
197+
return;
198+
}
199+
194200
const numberValue = Number(value);
195201
if (!isNaN(numberValue)) {
196202
obj[currentField] = numberValue;

tests/unit/common/config.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ import type { CliOptions } from "@mongosh/arg-parser";
55

66
describe("config", () => {
77
describe("env var parsing", () => {
8+
describe("mongodb urls", () => {
9+
it("should not try to parse a multiple-host urls", () => {
10+
const actual = setupUserConfig({
11+
env: {
12+
MDB_MCP_CONNECTION_STRING: "mongodb://user:password@host1,host2,host3/",
13+
},
14+
cli: [],
15+
defaults: defaultUserConfig,
16+
});
17+
18+
expect(actual.connectionString).toEqual("mongodb://user:password@host1,host2,host3/");
19+
});
20+
});
21+
822
describe("string cases", () => {
923
const testCases = [
1024
{ envVar: "MDB_MCP_API_BASE_URL", property: "apiBaseUrl", value: "http://test.com" },

0 commit comments

Comments
 (0)