From b8542f24a2765a6867269594512132db5be3b3f8 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Fri, 29 Aug 2025 14:22:22 +0200 Subject: [PATCH 1/4] chore: warn about the usage of deprecated cli arguments --- src/common/config.ts | 30 +++++++++++++++++++++++ tests/unit/common/config.test.ts | 41 ++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/common/config.ts b/src/common/config.ts index aebd6e73a..47f3577fc 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -251,6 +251,13 @@ function parseCliConfig(args: string[]): CliOptions { }; const positionalArguments = parsed._ ?? []; + + // we use console.warn here because we still don't have our logging system configured + // so we don't have a logger. For stdio, the warning will be received as a string in + // the client and IDEs like VSCode do show the message in the log window. For HTTP, + // it will be in the stdout of the process. + warnAboutDeprecatedCliArgs({ ...parsed, _: positionalArguments }, console.warn); + // if we have a positional argument that matches a connection string // store it as the connection specifier and remove it from the argument // list, so it doesn't get misunderstood by the mongosh args-parser @@ -262,6 +269,29 @@ function parseCliConfig(args: string[]): CliOptions { return parsed; } +export function warnAboutDeprecatedCliArgs( + args: CliOptions & + UserConfig & { + _?: string[]; + }, + warn: (msg: string) => void +): void { + console.log(args); + let wasWarned = false; + // the first position argument should be used + // instead of --connectionString, as it's how the mongosh works. + if (args.connectionString) { + wasWarned = true; + warn( + "The --connectionString argument is deprecated. Prefer using the first positional argument for the connection string or the MDB_MCP_CONNECTION_STRING environment variable." + ); + } + + if (wasWarned) { + warn("Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."); + } +} + function commaSeparatedToArray(str: string | string[] | undefined): T { if (str === undefined) { return [] as unknown as T; diff --git a/tests/unit/common/config.test.ts b/tests/unit/common/config.test.ts index 78257a3c0..32f1c4952 100644 --- a/tests/unit/common/config.test.ts +++ b/tests/unit/common/config.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect, vi, beforeEach } from "vitest"; import type { UserConfig } from "../../../src/common/config.js"; -import { setupUserConfig, defaultUserConfig } from "../../../src/common/config.js"; +import { setupUserConfig, defaultUserConfig, warnAboutDeprecatedCliArgs } from "../../../src/common/config.js"; +import { CliOptions } from "@mongosh/arg-parser"; describe("config", () => { describe("env var parsing", () => { @@ -605,3 +606,39 @@ describe("config", () => { }); }); }); + +describe("Deprecated CLI arguments", () => { + const referDocMessage = + "Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."; + + type TestCase = { readonly cliArg: keyof (CliOptions & UserConfig); readonly warning: string }; + const testCases = [ + { + cliArg: "connectionString", + warning: + "The --connectionString argument is deprecated. Prefer using the first positional argument for the connection string or the MDB_MCP_CONNECTION_STRING environment variable.", + }, + ] as TestCase[]; + + for (const { cliArg, warning } of testCases) { + describe(`deprecation behaviour of ${cliArg}`, () => { + let cliArgs: CliOptions & UserConfig & { _?: string[] }; + let warn: (msg: string) => void; + + beforeEach(() => { + cliArgs = { [cliArg]: "RandomString" } as unknown as CliOptions & UserConfig & { _?: string[] }; + warn = vi.fn(); + + warnAboutDeprecatedCliArgs(cliArgs, warn); + }); + + it(`warns the usage of ${cliArg} as it is deprecated`, () => { + expect(warn).toHaveBeenCalledWith(warning); + }); + + it(`shows the reference message when ${cliArg} was passed`, () => { + expect(warn).toHaveBeenCalledWith(referDocMessage); + }); + }); + } +}); From 1c5a80112bdd0f4bd3796aeec7e257f836074d56 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Fri, 29 Aug 2025 14:29:03 +0200 Subject: [PATCH 2/4] chore: make eslint happy :happy: --- tests/unit/common/config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/common/config.test.ts b/tests/unit/common/config.test.ts index 32f1c4952..789febff1 100644 --- a/tests/unit/common/config.test.ts +++ b/tests/unit/common/config.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import type { UserConfig } from "../../../src/common/config.js"; import { setupUserConfig, defaultUserConfig, warnAboutDeprecatedCliArgs } from "../../../src/common/config.js"; -import { CliOptions } from "@mongosh/arg-parser"; +import type { CliOptions } from "@mongosh/arg-parser"; describe("config", () => { describe("env var parsing", () => { From 47cd385fe2ec05610bd99d1990d5864728cff72e Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Fri, 29 Aug 2025 15:33:20 +0200 Subject: [PATCH 3/4] chore: pr improvements --- src/common/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/config.ts b/src/common/config.ts index 78150541f..e86af037e 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -279,17 +279,17 @@ export function warnAboutDeprecatedCliArgs( warn: (msg: string) => void ): void { console.log(args); - let wasWarned = false; + let usedDeprecatedArgument = false; // the first position argument should be used // instead of --connectionString, as it's how the mongosh works. if (args.connectionString) { - wasWarned = true; + usedDeprecatedArgument = true; warn( "The --connectionString argument is deprecated. Prefer using the first positional argument for the connection string or the MDB_MCP_CONNECTION_STRING environment variable." ); } - if (wasWarned) { + if (usedDeprecatedArgument) { warn("Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."); } } From a06dbf847868055edba8cef4bf34fbf3e29a198c Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Mon, 1 Sep 2025 11:36:25 +0200 Subject: [PATCH 4/4] chore: leftovers --- src/common/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/config.ts b/src/common/config.ts index e86af037e..4bc02efe9 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -278,7 +278,6 @@ export function warnAboutDeprecatedCliArgs( }, warn: (msg: string) => void ): void { - console.log(args); let usedDeprecatedArgument = false; // the first position argument should be used // instead of --connectionString, as it's how the mongosh works.