Skip to content

Commit bd93e3d

Browse files
committed
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into gagik/query-header-override
2 parents d11ec6b + 6325422 commit bd93e3d

31 files changed

+256
-129
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,12 @@ You can disable telemetry using:
500500

501501
The MongoDB MCP Server may offer functionality that is still in development and may change in future releases. These features are considered "preview features" and are not enabled by default. Generally, these features are well tested, but may not offer the complete functionality we intend to provide in the final release or we'd like to gather feedback before making them generally available. To enable one or more preview features, use the `previewFeatures` configuration option.
502502

503-
- For **environment variable** configuration, use a comma-separated string: `export MDB_MCP_PREVIEW_FEATURES="vectorSearch,feature1,feature2"`.
504-
- For **command-line argument** configuration, use a space-separated string: `--previewFeatures vectorSearch feature1 feature2`.
503+
- For **environment variable** configuration, use a comma-separated string: `export MDB_MCP_PREVIEW_FEATURES="search,feature1,feature2"`.
504+
- For **command-line argument** configuration, use a space-separated string: `--previewFeatures search feature1 feature2`.
505505

506506
List of available preview features:
507507

508-
- `vectorSearch` - Enables tools or functionality related to Vector Search in MongoDB Atlas:
508+
- `search` - Enables tools or functionality related to Atlas Search and Vector Search in MongoDB Atlas:
509509
- Index management, such as creating, listing, and dropping search and vector search indexes.
510510
- Querying collections using vector search capabilities. This requires a configured embedding model that will be used to generate vector representations of the query data. Currently, only [Voyage AI](https://www.voyageai.com) embedding models are supported. Set the `voyageApiKey` configuration option with your Voyage AI API key to use this feature.
511511

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@
6666
"generate": "pnpm run generate:api && pnpm run generate:arguments",
6767
"generate:api": "./scripts/generate.sh",
6868
"generate:arguments": "tsx scripts/generateArguments.ts",
69+
"pretest": "pnpm run build",
6970
"test": "vitest --project eslint-rules --project unit-and-integration --coverage --run",
70-
"pretest:accuracy": "pnpm run build",
7171
"test:accuracy": "sh ./scripts/accuracy/runAccuracyTests.sh",
7272
"test:long-running-tests": "vitest --project long-running-tests --coverage",
73+
"test:local": "SKIP_ATLAS_TESTS=true SKIP_ATLAS_LOCAL_TESTS=true pnpm run test",
7374
"atlas:cleanup": "vitest --project atlas-cleanup"
7475
},
7576
"license": "Apache-2.0",

src/common/config/argsParserOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const OPTIONS = {
6060
boolean: [
6161
"apiDeprecationErrors",
6262
"apiStrict",
63+
"dryRun",
6364
"embeddingsValidation",
6465
"help",
6566
"indexCheck",

src/common/config/createUserConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ function registerKnownSecretsInRootKeychain(userConfig: Partial<UserConfig>): vo
170170
}
171171

172172
function warnIfVectorSearchNotEnabledCorrectly(config: UserConfig, warn: (message: string) => void): void {
173-
const vectorSearchEnabled = config.previewFeatures.includes("vectorSearch");
173+
const searchEnabled = config.previewFeatures.includes("search");
174174
const embeddingsProviderConfigured = !!config.voyageApiKey;
175-
if (vectorSearchEnabled && !embeddingsProviderConfigured) {
175+
if (searchEnabled && !embeddingsProviderConfigured) {
176176
warn(`\
177177
Warning: Vector search is enabled but no embeddings provider is configured.
178178
- Set an embeddings provider configuration option to enable auto-embeddings during document insertion and text-based queries with $vectorSearch.\
179179
`);
180180
}
181181

182-
if (!vectorSearchEnabled && embeddingsProviderConfigured) {
182+
if (!searchEnabled && embeddingsProviderConfigured) {
183183
warn(`\
184-
Warning: An embeddings provider is configured but the 'vectorSearch' preview feature is not enabled.
185-
- Enable vector search by adding 'vectorSearch' to the 'previewFeatures' configuration option, or remove the embeddings provider configuration if not needed.\
184+
Warning: An embeddings provider is configured but the 'search' preview feature is not enabled.
185+
- Enable vector search by adding 'search' to the 'previewFeatures' configuration option, or remove the embeddings provider configuration if not needed.\
186186
`);
187187
}
188188
}

src/common/config/userConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,11 @@ export const UserConfigSchema = z4.object({
214214
"When set to true, allows configuration values to be overridden via request headers and query parameters."
215215
)
216216
.register(configRegistry, { overrideBehavior: "not-allowed" }),
217+
dryRun: z4
218+
.boolean()
219+
.default(false)
220+
.describe(
221+
"When true, runs the server in dry mode: dumps configuration and enabled tools, then exits without starting the server."
222+
)
223+
.register(configRegistry, { overrideBehavior: "not-allowed" }),
217224
});

src/common/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const previewFeatureValues = ["vectorSearch"] as const;
1+
export const previewFeatureValues = ["search"] as const;
22
export type PreviewFeature = (typeof previewFeatureValues)[number];
33

44
export const similarityValues = ["cosine", "euclidean", "dotProduct"] as const;

src/common/search/embeddingsProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class VoyageEmbeddingsProvider implements EmbeddingsProvider<VoyageModels, Voyag
4141
}
4242

4343
static isConfiguredIn({ voyageApiKey, previewFeatures }: UserConfig): boolean {
44-
return previewFeatures.includes("vectorSearch") && !!voyageApiKey;
44+
return previewFeatures.includes("search") && !!voyageApiKey;
4545
}
4646

4747
async embed<Model extends VoyageModels>(

src/index.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,23 @@ import { StdioRunner } from "./transports/stdio.js";
4444
import { StreamableHttpRunner } from "./transports/streamableHttp.js";
4545
import { systemCA } from "@mongodb-js/devtools-proxy-support";
4646
import { Keychain } from "./common/keychain.js";
47+
import { DryRunModeRunner } from "./transports/dryModeRunner.js";
4748

4849
async function main(): Promise<void> {
4950
systemCA().catch(() => undefined); // load system CA asynchronously as in mongosh
5051

5152
const config = createUserConfig();
52-
assertHelpMode(config);
53-
assertVersionMode(config);
53+
if (config.help) {
54+
handleHelpRequest();
55+
}
56+
57+
if (config.version) {
58+
handleVersionRequest();
59+
}
60+
61+
if (config.dryRun) {
62+
await handleDryRunRequest(config);
63+
}
5464

5565
const transportRunner =
5666
config.transport === "stdio"
@@ -133,17 +143,35 @@ main().catch((error: unknown) => {
133143
process.exit(1);
134144
});
135145

136-
function assertHelpMode(config: UserConfig): void | never {
137-
if (config.help) {
138-
console.log("For usage information refer to the README.md:");
139-
console.log("https://github.com/mongodb-js/mongodb-mcp-server?tab=readme-ov-file#quick-start");
140-
process.exit(0);
141-
}
146+
function handleHelpRequest(): never {
147+
console.log("For usage information refer to the README.md:");
148+
console.log("https://github.com/mongodb-js/mongodb-mcp-server?tab=readme-ov-file#quick-start");
149+
process.exit(0);
142150
}
143151

144-
function assertVersionMode(config: UserConfig): void | never {
145-
if (config.version) {
146-
console.log(packageInfo.version);
152+
function handleVersionRequest(): never {
153+
console.log(packageInfo.version);
154+
process.exit(0);
155+
}
156+
157+
export async function handleDryRunRequest(config: UserConfig): Promise<never> {
158+
try {
159+
const runner = new DryRunModeRunner({
160+
userConfig: config,
161+
logger: {
162+
log(message): void {
163+
console.log(message);
164+
},
165+
error(message): void {
166+
console.error(message);
167+
},
168+
},
169+
});
170+
await runner.start();
171+
await runner.close();
147172
process.exit(0);
173+
} catch (error) {
174+
console.error(`Fatal error running server in dry run mode: ${error as string}`);
175+
process.exit(1);
148176
}
149177
}

src/tools/mongodb/create/createIndex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export class CreateIndexTool extends MongoDBToolBase {
7676
type: z.literal("classic"),
7777
keys: z.object({}).catchall(z.custom<IndexDirection>()).describe("The index definition"),
7878
}),
79-
...(this.isFeatureEnabled("vectorSearch") ? [this.vectorSearchIndexDefinition] : []),
79+
...(this.isFeatureEnabled("search") ? [this.vectorSearchIndexDefinition] : []),
8080
])
8181
)
8282
.describe(
83-
`The index definition. Use 'classic' for standard indexes${this.isFeatureEnabled("vectorSearch") ? " and 'vectorSearch' for vector search indexes" : ""}.`
83+
`The index definition. Use 'classic' for standard indexes${this.isFeatureEnabled("search") ? " and 'vectorSearch' for vector search indexes" : ""}.`
8484
),
8585
};
8686

src/tools/mongodb/create/insertMany.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class InsertManyTool extends MongoDBToolBase {
2525
.describe(
2626
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany()."
2727
),
28-
...(this.isFeatureEnabled("vectorSearch")
28+
...(this.isFeatureEnabled("search")
2929
? {
3030
embeddingParameters: zSupportedEmbeddingParametersWithInput
3131
.optional()
@@ -45,7 +45,7 @@ export class InsertManyTool extends MongoDBToolBase {
4545
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
4646
const provider = await this.ensureConnected();
4747

48-
const embeddingParameters = this.isFeatureEnabled("vectorSearch")
48+
const embeddingParameters = this.isFeatureEnabled("search")
4949
? (providedEmbeddingParameters as z.infer<typeof zSupportedEmbeddingParametersWithInput>)
5050
: undefined;
5151

0 commit comments

Comments
 (0)