Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ function parseEnvConfig(env: Record<string, unknown>): Partial<UserConfig> {
return;
}
if (path.length === 0) {
// MongoDB URLs must not be preprocessed
if (typeof value === "string" && (value.startsWith("mongodb://") || value.startsWith("mongodb+srv://"))) {
obj[currentField] = value;
return;
}

const numberValue = Number(value);
if (!isNaN(numberValue)) {
obj[currentField] = numberValue;
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/common/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import type { CliOptions } from "@mongosh/arg-parser";

describe("config", () => {
describe("env var parsing", () => {
describe("mongodb urls", () => {
it("should not try to parse a multiple-host urls", () => {
const actual = setupUserConfig({
env: {
MDB_MCP_CONNECTION_STRING: "mongodb://user:password@host1,host2,host3/",
},
cli: [],
defaults: defaultUserConfig,
});

expect(actual.connectionString).toEqual("mongodb://user:password@host1,host2,host3/");
});
});

describe("string cases", () => {
const testCases = [
{ envVar: "MDB_MCP_API_BASE_URL", property: "apiBaseUrl", value: "http://test.com" },
Expand Down Expand Up @@ -60,6 +74,16 @@ describe("config", () => {
});

describe("cli parsing", () => {
it("should not try to parse a multiple-host urls", () => {
const actual = setupUserConfig({
cli: ["myself", "--", "--connectionString", "mongodb://user:password@host1,host2,host3/"],
env: {},
defaults: defaultUserConfig,
});

expect(actual.connectionString).toEqual("mongodb://user:password@host1,host2,host3/");
});

describe("string use cases", () => {
const testCases = [
{
Expand Down
Loading