Skip to content

Commit fbb3d0f

Browse files
chore: add warning when vector search is not correctly configured
1 parent 5cd2e51 commit fbb3d0f

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/common/config.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export function warnAboutDeprecatedOrUnknownCliArgs(
319319
if (knownArgs.connectionString) {
320320
usedDeprecatedArgument = true;
321321
warn(
322-
"The --connectionString argument is deprecated. Prefer using the MDB_MCP_CONNECTION_STRING environment variable or the first positional argument for the connection string."
322+
"Warning: The --connectionString argument is deprecated. Prefer using the MDB_MCP_CONNECTION_STRING environment variable or the first positional argument for the connection string."
323323
);
324324
}
325325

@@ -333,15 +333,15 @@ export function warnAboutDeprecatedOrUnknownCliArgs(
333333
if (!valid) {
334334
usedInvalidArgument = true;
335335
if (suggestion) {
336-
warn(`Invalid command line argument '${providedKey}'. Did you mean '${suggestion}'?`);
336+
warn(`Warning: Invalid command line argument '${providedKey}'. Did you mean '${suggestion}'?`);
337337
} else {
338-
warn(`Invalid command line argument '${providedKey}'.`);
338+
warn(`Warning: Invalid command line argument '${providedKey}'.`);
339339
}
340340
}
341341
}
342342

343343
if (usedInvalidArgument || usedDeprecatedArgument) {
344-
warn("Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.");
344+
warn("- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.");
345345
}
346346

347347
if (usedInvalidArgument) {
@@ -372,6 +372,24 @@ export function registerKnownSecretsInRootKeychain(userConfig: Partial<UserConfi
372372
maybeRegister(userConfig.username, "user");
373373
}
374374

375+
function warnIfVectorSearchNotEnabledCorrectly(config: UserConfig): void {
376+
const vectorSearchEnabled = config.previewFeatures.includes("vectorSearch");
377+
const embeddingsProviderConfigured = !!config.voyageApiKey;
378+
if (vectorSearchEnabled && !embeddingsProviderConfigured) {
379+
console.warn(`\
380+
Warning: Vector search is enabled but no embeddings provider is configured.
381+
- Set the 'voyageApiKey' configuration option to enable auto-embeddings during document insertion and text-based queries with $vectorSearch.\
382+
`);
383+
}
384+
385+
if (!vectorSearchEnabled && embeddingsProviderConfigured) {
386+
console.warn(`\
387+
Warning: An embeddings provider is configured but the 'vectorSearch' preview feature is not enabled.
388+
- Enable vector search by adding 'vectorSearch' to the 'previewFeatures' configuration option, or remove the embeddings provider configuration if not needed.\
389+
`);
390+
}
391+
}
392+
375393
export function setupUserConfig({ cli, env }: { cli: string[]; env: Record<string, unknown> }): UserConfig {
376394
const rawConfig = {
377395
...parseEnvConfig(env),
@@ -392,6 +410,7 @@ export function setupUserConfig({ cli, env }: { cli: string[]; env: Record<strin
392410
// We don't have as schema defined for all args-parser arguments so we need to merge the raw config with the parsed config.
393411
const userConfig = { ...rawConfig, ...parseResult.data } as UserConfig;
394412

413+
warnIfVectorSearchNotEnabledCorrectly(userConfig);
395414
registerKnownSecretsInRootKeychain(userConfig);
396415
return userConfig;
397416
}

tests/unit/common/config.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,14 @@ describe("config", () => {
686686

687687
describe("CLI arguments", () => {
688688
const referDocMessage =
689-
"Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.";
689+
"- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server.";
690690

691691
type TestCase = { readonly cliArg: keyof (CliOptions & UserConfig); readonly warning: string };
692692
const testCases = [
693693
{
694694
cliArg: "connectionString",
695695
warning:
696-
"The --connectionString argument is deprecated. Prefer using the MDB_MCP_CONNECTION_STRING environment variable or the first positional argument for the connection string.",
696+
"Warning: The --connectionString argument is deprecated. Prefer using the MDB_MCP_CONNECTION_STRING environment variable or the first positional argument for the connection string.",
697697
},
698698
] as TestCase[];
699699

@@ -742,9 +742,9 @@ describe("CLI arguments", () => {
742742
{ warn, exit }
743743
);
744744

745-
expect(warn).toHaveBeenCalledWith("Invalid command line argument 'wakanda'.");
745+
expect(warn).toHaveBeenCalledWith("Warning: Invalid command line argument 'wakanda'.");
746746
expect(warn).toHaveBeenCalledWith(
747-
"Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
747+
"- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
748748
);
749749
});
750750

@@ -767,9 +767,11 @@ describe("CLI arguments", () => {
767767
{ warn, exit }
768768
);
769769

770-
expect(warn).toHaveBeenCalledWith("Invalid command line argument 'readonli'. Did you mean 'readOnly'?");
771770
expect(warn).toHaveBeenCalledWith(
772-
"Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
771+
"Warning: Invalid command line argument 'readonli'. Did you mean 'readOnly'?"
772+
);
773+
expect(warn).toHaveBeenCalledWith(
774+
"- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
773775
);
774776
});
775777

@@ -781,9 +783,11 @@ describe("CLI arguments", () => {
781783
{ warn, exit }
782784
);
783785

784-
expect(warn).toHaveBeenCalledWith("Invalid command line argument 'readonly'. Did you mean 'readOnly'?");
785786
expect(warn).toHaveBeenCalledWith(
786-
"Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
787+
"Warning: Invalid command line argument 'readonly'. Did you mean 'readOnly'?"
788+
);
789+
expect(warn).toHaveBeenCalledWith(
790+
"- Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."
787791
);
788792
});
789793
});

0 commit comments

Comments
 (0)