Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
438 changes: 438 additions & 0 deletions CONFIGURATION.md

Large diffs are not rendered by default.

374 changes: 1 addition & 373 deletions README.md

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions scripts/generateArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This script generates argument definitions and updates:
* - server.json arrays
* - README.md configuration table
* - CONFIGURATION.md configuration table
*
* It uses the Zod schema and OPTIONS defined in src/common/config.ts
*/
Expand Down Expand Up @@ -244,7 +244,7 @@ function updateServerJsonEnvVars(envVars: ArgumentInfo[]): void {
console.log(`✓ Updated server.json (version ${version})`);
}

function generateReadmeConfigTable(argumentInfos: ArgumentInfo[]): string {
function generateConfigurationTable(argumentInfos: ArgumentInfo[]): string {
const rows = [
"| CLI Option | Environment Variable | Default | Description |",
"| -------------------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |",
Expand Down Expand Up @@ -275,6 +275,10 @@ function generateReadmeConfigTable(argumentInfos: ArgumentInfo[]): string {
case "string":
defaultValueString = `\`"${defaultValue}"\``;
break;
case "object": {
defaultValueString = `\`"${JSON.stringify(defaultValue)}"\``;
break;
}
default:
throw new Error(`Unsupported default value type: ${typeof defaultValue}`);
}
Expand All @@ -290,31 +294,31 @@ function generateReadmeConfigTable(argumentInfos: ArgumentInfo[]): string {
return rows.join("\n");
}

function updateReadmeConfigTable(envVars: ArgumentInfo[]): void {
const readmePath = join(__dirname, "..", "README.md");
let content = readFileSync(readmePath, "utf-8");
function updateConfigurationTable(envVars: ArgumentInfo[]): void {
const configurationPath = join(__dirname, "..", "CONFIGURATION.md");
let content = readFileSync(configurationPath, "utf-8");

const newTable = generateReadmeConfigTable(envVars);
const newTable = generateConfigurationTable(envVars);

// Find and replace the configuration options table
const tableRegex = /### Configuration Options\n\n\| CLI Option[\s\S]*?\n\n####/;
const replacement = `### Configuration Options\n\n${newTable}\n\n####`;
const tableRegex = /## Configuration Options\n\n\| CLI Option[\s\S]*?\n\n###/;
const replacement = `## Configuration Options\n\n${newTable}\n\n###`;

content = content.replace(tableRegex, replacement);

writeFileSync(readmePath, content, "utf-8");
console.log("✓ Updated README.md configuration table");
writeFileSync(configurationPath, content, "utf-8");
console.log("✓ Updated CONFIGURATION.md configuration table");

// Run prettier on the README.md file
execSync("npx prettier --write README.md", { cwd: join(__dirname, "..") });
// Run prettier on the CONFIGURATION.md file
execSync("npx prettier --write CONFIGURATION.md", { cwd: join(__dirname, "..") });
}

function main(): void {
const zodMetadata = extractZodDescriptions();

const argumentInfo = getArgumentInfo(OPTIONS, zodMetadata);
updateServerJsonEnvVars(argumentInfo);
updateReadmeConfigTable(argumentInfo);
updateConfigurationTable(argumentInfo);
}

main();
26 changes: 26 additions & 0 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@
"format": "string",
"isSecret": false
},
{
"name": "MDB_MCP_TOOL_METADATA_OVERRIDES",
"description": "A map of name of the MongoDB MCP server tool to the metadata that needs to be used for that tool. Example: `{ \"toolMetadataOverrides\": { \"find\": { \"name\": \"query\" } } }`",
"isRequired": false,
"format": "string",
"isSecret": false
},
{
"name": "MDB_MCP_TRANSPORT",
"description": "Either 'stdio' or 'http'.",
Expand Down Expand Up @@ -323,6 +330,12 @@
"description": "When set to disabled, disables telemetry collection.",
"isRequired": false
},
{
"type": "named",
"name": "--toolMetadataOverrides",
"description": "A map of name of the MongoDB MCP server tool to the metadata that needs to be used for that tool. Example: `{ \"toolMetadataOverrides\": { \"find\": { \"name\": \"query\" } } }`",
"isRequired": false
},
{
"type": "named",
"name": "--transport",
Expand Down Expand Up @@ -498,6 +511,13 @@
"format": "string",
"isSecret": false
},
{
"name": "MDB_MCP_TOOL_METADATA_OVERRIDES",
"description": "A map of name of the MongoDB MCP server tool to the metadata that needs to be used for that tool. Example: `{ \"toolMetadataOverrides\": { \"find\": { \"name\": \"query\" } } }`",
"isRequired": false,
"format": "string",
"isSecret": false
},
{
"name": "MDB_MCP_TRANSPORT",
"description": "Either 'stdio' or 'http'.",
Expand Down Expand Up @@ -651,6 +671,12 @@
"description": "When set to disabled, disables telemetry collection.",
"isRequired": false
},
{
"type": "named",
"name": "--toolMetadataOverrides",
"description": "A map of name of the MongoDB MCP server tool to the metadata that needs to be used for that tool. Example: `{ \"toolMetadataOverrides\": { \"find\": { \"name\": \"query\" } } }`",
"isRequired": false
},
{
"type": "named",
"name": "--transport",
Expand Down
5 changes: 5 additions & 0 deletions src/common/config/argsParserOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export const OPTIONS = {
"exportTimeoutMs",
"exportCleanupIntervalMs",
"voyageApiKey",
// Note: toolMetadataOverrides expects a JSON object but we mention it
// as a string only to let yargs-parser know that this key needs to be
// parsed. The internal handling of the key as an object is done within
// yargs-parser itself.
"toolMetadataOverrides",
],
boolean: [
"apiDeprecationErrors",
Expand Down
4 changes: 4 additions & 0 deletions src/common/config/createUserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function parseUserConfigSources(cliArguments: string[]): {
...OPTIONS,
// This helps parse the relevant environment variables.
envPrefix: "MDB_MCP_",
// This is the name of key that yargs-parser will look up in CLI
// arguments (--config) and ENV variables (MDB_MCP_CONFIG) to load an
// initial configuration from.
config: "config",
configuration: {
...OPTIONS.configuration,
// Setting this to true will populate `_` variable which is
Expand Down
12 changes: 12 additions & 0 deletions src/common/config/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ export const UserConfigSchema = z4.object({
)
.default([])
.describe("An array of preview features that are enabled."),
toolMetadataOverrides: z4
.record(
z4.string().describe("Original name of the MongoDB MCP server tool that needs to be overridden."),
z4.object({
name: z4.string().nonempty().optional().describe("New name to be used for the tool."),
description: z4.string().nonempty().optional().describe("New description to be used for the tool."),
})
)
.default({})
.describe(
'A map of name of the MongoDB MCP server tool to the metadata that needs to be used for that tool. Example: `{ "toolMetadataOverrides": { "find": { "name": "query" } } }`'
),
});
14 changes: 14 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,27 @@ export class Server {
}

private registerTools(): void {
const toolsToRegister: ToolBase[] = [];
const usedNames = new Set<string>();

for (const toolConstructor of this.toolConstructors) {
const tool = new toolConstructor({
session: this.session,
config: this.userConfig,
telemetry: this.telemetry,
elicitation: this.elicitation,
});

if (usedNames.has(tool.name)) {
throw new Error(
`Tool name collision detected: '${tool.name}'. This might be due to toolMetadataOverrides configuration.`
);
}
usedNames.add(tool.name);
toolsToRegister.push(tool);
}

for (const tool of toolsToRegister) {
if (tool.register(this)) {
this.tools.push(tool);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/atlas/connect/connectCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const ConnectClusterArgs = {
};

export class ConnectClusterTool extends AtlasToolBase {
public name = "atlas-connect-cluster";
protected description = "Connect to MongoDB Atlas cluster";
public internalName = "atlas-connect-cluster";
protected internalDescription = "Connect to MongoDB Atlas cluster";
public operationType: OperationType = "connect";
protected argsShape = {
...ConnectClusterArgs,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/atlas/create/createAccessList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const CreateAccessListArgs = {
};

export class CreateAccessListTool extends AtlasToolBase {
public name = "atlas-create-access-list";
protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
public internalName = "atlas-create-access-list";
protected internalDescription = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
public operationType: OperationType = "create";
protected argsShape = {
...CreateAccessListArgs,
Expand Down
Loading
Loading