Skip to content

Commit a91e08e

Browse files
committed
docs: list all available tools with a generate script MCP-340
1 parent fbc59fa commit a91e08e

File tree

7 files changed

+233
-43
lines changed

7 files changed

+233
-43
lines changed

README.md

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -283,49 +283,54 @@ npx -y mongodb-mcp-server@latest --transport http --httpHost=0.0.0.0 --httpPort=
283283

284284
#### MongoDB Atlas Tools
285285

286-
- `atlas-list-orgs` - Lists MongoDB Atlas organizations
287-
- `atlas-list-projects` - Lists MongoDB Atlas projects
288-
- `atlas-create-project` - Creates a new MongoDB Atlas project
289-
- `atlas-list-clusters` - Lists MongoDB Atlas clusters
290-
- `atlas-inspect-cluster` - Inspect a specific MongoDB Atlas cluster
286+
- `atlas-connect-cluster` - Connect to MongoDB Atlas cluster
287+
- `atlas-create-access-list` - Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.
288+
- `atlas-create-db-user` - Create an MongoDB Atlas database user
291289
- `atlas-create-free-cluster` - Create a free MongoDB Atlas cluster
292-
- `atlas-connect-cluster` - Connects to MongoDB Atlas cluster
293-
- `atlas-inspect-access-list` - Inspect IP/CIDR ranges with access to MongoDB Atlas clusters
294-
- `atlas-create-access-list` - Configure IP/CIDR access list for MongoDB Atlas clusters
290+
- `atlas-create-project` - Create a MongoDB Atlas project
291+
- `atlas-get-performance-advisor` - Get MongoDB Atlas performance advisor recommendations, which includes the operations: suggested indexes, drop index suggestions, schema suggestions, and a sample of the most recent (max 50) slow query logs
292+
- `atlas-inspect-access-list` - Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.
293+
- `atlas-inspect-cluster` - Inspect MongoDB Atlas cluster
294+
- `atlas-list-alerts` - List MongoDB Atlas alerts
295+
- `atlas-list-clusters` - List MongoDB Atlas clusters
295296
- `atlas-list-db-users` - List MongoDB Atlas database users
296-
- `atlas-create-db-user` - Creates a MongoDB Atlas database user
297-
- `atlas-list-alerts` - List MongoDB Atlas Alerts for a Project
298-
- `atlas-get-performance-advisor` - Gets Atlas Performance Advisor recommendations (index suggestions, drop index suggestions, schema suggestions, slow query logs)
297+
- `atlas-list-orgs` - List MongoDB Atlas organizations
298+
- `atlas-list-projects` - List MongoDB Atlas projects
299299

300300
NOTE: atlas tools are only available when you set credentials on [configuration](#configuration) section.
301301

302302
#### MongoDB Atlas Local Tools
303303

304-
- `atlas-local-list-deployments` - Lists MongoDB Atlas Local deployments
305-
- `atlas-local-create-deployment` - Creates a MongoDB Atlas Local deployment
306-
- `atlas-local-connect-deployment` - Connects to a MongoDB Atlas Local deployment
307-
- `atlas-local-delete-deployment` - Deletes a MongoDB Atlas Local deployment
304+
- `atlas-local-connect-deployment` - Connect to a MongoDB Atlas Local deployment
305+
- `atlas-local-create-deployment` - Create a MongoDB Atlas local deployment
306+
- `atlas-local-delete-deployment` - Delete a MongoDB Atlas local deployment
307+
- `atlas-local-list-deployments` - List MongoDB Atlas local deployments
308308

309309
#### MongoDB Database Tools
310310

311-
- `connect` - Connect to a MongoDB instance
312-
- `find` - Run a find query against a MongoDB collection. The number of documents returned is limited by the `limit` parameter and the server's `maxDocumentsPerQuery` configuration, whichever is smaller. The total size of the returned documents is also limited by the `responseBytesLimit` parameter and the server's `maxBytesPerQuery` configuration, whichever is smaller.
313-
- `aggregate` - Run an aggregation against a MongoDB collection. The number of documents returned is limited by the server's `maxDocumentsPerQuery` configuration. The total size of the returned documents is also limited by the `responseBytesLimit` parameter and the server's `maxBytesPerQuery` configuration, whichever is smaller.
314-
- `count` - Get the number of documents in a MongoDB collection
315-
- `insert-many` - Insert multiple documents into a MongoDB collection
316-
- `create-index` - Create an index for a MongoDB collection
317-
- `update-many` - Update multiple documents in a MongoDB collection
318-
- `rename-collection` - Rename a MongoDB collection
319-
- `delete-many` - Delete multiple documents from a MongoDB collection
320-
- `drop-collection` - Remove a collection from a MongoDB database
321-
- `drop-database` - Remove a MongoDB database
322-
- `list-databases` - List all databases for a MongoDB connection
323-
- `list-collections` - List all collections for a given database
311+
- `aggregate` - Run an aggregation against a MongoDB collection
324312
- `collection-indexes` - Describe the indexes for a collection
325313
- `collection-schema` - Describe the schema for a collection
326-
- `collection-storage-size` - Get the size of a collection in MB
327-
- `db-stats` - Return statistics about a MongoDB database
328-
- `export` - Export query or aggregation results to EJSON format. Creates a uniquely named export accessible via the `exported-data` resource.
314+
- `collection-storage-size` - Gets the size of the collection
315+
- `connect` - Connect to a MongoDB instance
316+
- `count` - Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter
317+
- `create-collection` - Creates a new collection in a database. If the database doesn't exist, it will be created automatically.
318+
- `create-index` - Create an index for a collection
319+
- `db-stats` - Returns statistics that reflect the use state of a single database
320+
- `delete-many` - Removes all documents that match the filter from a MongoDB collection
321+
- `drop-collection` - Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.
322+
- `drop-database` - Removes the specified database, deleting the associated data files
323+
- `drop-index` - Drop an index for the provided database and collection.
324+
- `explain` - Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method
325+
- `export` - Export a query or aggregation results in the specified EJSON format.
326+
- `find` - Run a find query against a MongoDB collection
327+
- `insert-many` - Insert an array of documents into a MongoDB collection
328+
- `list-collections` - List all collections for a given database
329+
- `list-databases` - List all databases for a MongoDB connection
330+
- `mongodb-logs` - Returns the most recent logged mongod events
331+
- `rename-collection` - Renames a collection in a MongoDB database
332+
- `switch-connection` - Switch to a different MongoDB connection
333+
- `update-many` - Updates all documents that match the specified filter for a collection
329334

330335
## 📄 Supported Resources
331336

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"reformat": "prettier --write .",
6666
"generate": "pnpm run generate:api && pnpm run generate:arguments",
6767
"generate:api": "./scripts/generate.sh",
68-
"generate:arguments": "tsx scripts/generateArguments.ts",
68+
"generate:arguments": "tsx scripts/generate/index.ts",
6969
"pretest": "pnpm run build",
7070
"test": "vitest --project eslint-rules --project unit-and-integration --coverage --run",
7171
"test:accuracy": "sh ./scripts/accuracy/runAccuracyTests.sh",

scripts/generate/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generate Scripts
2+
3+
This folder contains a helper script which generates various documentation and configurations based on our code.
4+
5+
## Files
6+
7+
- **`index.ts`** - Main entry point that orchestrates all generation tasks
8+
- **`generateArguments.ts`** - Generates CLI arguments, environment variables, and configuration tables from the UserConfig Zod Schema
9+
- **`generateToolDocumentation.ts`** - Generates tool documentation by reading from the AllTools array
10+
11+
## Usage
12+
13+
Run all generators:
14+
15+
```bash
16+
pnpm run generate:arguments
17+
```
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env tsx
2-
31
/**
42
* This script generates argument definitions and updates:
53
* - server.json arrays
@@ -11,7 +9,7 @@
119
import { readFileSync, writeFileSync } from "fs";
1210
import { join, dirname } from "path";
1311
import { fileURLToPath } from "url";
14-
import { UserConfigSchema, configRegistry } from "../src/common/config/userConfig.js";
12+
import { UserConfigSchema, configRegistry } from "../../src/common/config/userConfig.js";
1513
import { execSync } from "child_process";
1614
import type { z as z4 } from "zod/v4";
1715

@@ -205,8 +203,8 @@ function generatePackageArguments(envVars: ArgumentInfo[]): unknown[] {
205203
}
206204

207205
function updateServerJsonEnvVars(envVars: ArgumentInfo[]): void {
208-
const serverJsonPath = join(__dirname, "..", "server.json");
209-
const packageJsonPath = join(__dirname, "..", "package.json");
206+
const serverJsonPath = join(__dirname, "..", "..", "server.json");
207+
const packageJsonPath = join(__dirname, "..", "..", "package.json");
210208

211209
const content = readFileSync(serverJsonPath, "utf-8");
212210
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version: string };
@@ -310,7 +308,7 @@ function generateReadmeConfigTable(argumentInfos: ArgumentInfo[]): string {
310308
}
311309

312310
function updateReadmeConfigTable(envVars: ArgumentInfo[]): void {
313-
const readmePath = join(__dirname, "..", "README.md");
311+
const readmePath = join(__dirname, "..", "..", "README.md");
314312
let content = readFileSync(readmePath, "utf-8");
315313

316314
const newTable = generateReadmeConfigTable(envVars);
@@ -325,15 +323,13 @@ function updateReadmeConfigTable(envVars: ArgumentInfo[]): void {
325323
console.log("✓ Updated README.md configuration table");
326324

327325
// Run prettier on the README.md file
328-
execSync("npx prettier --write README.md", { cwd: join(__dirname, "..") });
326+
execSync("npx prettier --write README.md", { cwd: join(__dirname, "..", "..") });
329327
}
330328

331-
function main(): void {
329+
export function generateArguments(): void {
332330
const zodMetadata = extractZodDescriptions();
333-
334331
const argumentInfo = getArgumentInfo(zodMetadata);
335332
updateServerJsonEnvVars(argumentInfo);
336333
updateReadmeConfigTable(argumentInfo);
337334
}
338335

339-
main();
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/**
2+
* This script generates tool documentation and updates:
3+
* - README.md tools list
4+
*
5+
* It uses the AllTools array from the tools module.
6+
*/
7+
8+
import { readFileSync, writeFileSync } from "fs";
9+
import { join, dirname } from "path";
10+
import { fileURLToPath } from "url";
11+
import { AllTools } from "../../src/tools/index.js";
12+
13+
const __filename = fileURLToPath(import.meta.url);
14+
const __dirname = dirname(__filename);
15+
16+
interface ToolInfo {
17+
name: string;
18+
description: string;
19+
category: string;
20+
operationType: string;
21+
}
22+
23+
const overrides: Record<string, string> = {
24+
connect: "Connect to a MongoDB instance",
25+
"switch-connection": "Switch to a different MongoDB connection",
26+
};
27+
28+
function extractToolInformation(): ToolInfo[] {
29+
const tools: ToolInfo[] = [];
30+
31+
for (const ToolClass of AllTools) {
32+
// Create a minimal instance to access instance properties
33+
// We need to provide dummy params since we only need name and description
34+
const dummyParams = {
35+
category: ToolClass.category,
36+
operationType: ToolClass.operationType,
37+
session: {
38+
on: () => {},
39+
off: () => {},
40+
emit: () => false,
41+
connectionManager: null,
42+
} as never,
43+
config: {
44+
previewFeatures: [],
45+
vectorSearchDimensions: 1024,
46+
vectorSearchModel: "voyage-3-large",
47+
readOnly: false,
48+
disabledTools: [],
49+
} as never,
50+
telemetry: {
51+
emitEvents: () => {},
52+
} as never,
53+
elicitation: {
54+
requestConfirmation: () => Promise.resolve(false),
55+
} as never,
56+
};
57+
58+
try {
59+
const instance = new ToolClass(dummyParams);
60+
// Access the protected description property
61+
const description =
62+
(instance as unknown as { description?: string }).description || "No description available";
63+
tools.push({
64+
name: instance.name,
65+
description: overrides[instance.name] || description,
66+
category: ToolClass.category,
67+
operationType: ToolClass.operationType,
68+
});
69+
} catch (error) {
70+
console.error(`Error instantiating tool ${ToolClass.name}:`, error);
71+
}
72+
}
73+
74+
// Sort by category first, then by name
75+
return tools.sort((a, b) => {
76+
if (a.category !== b.category) {
77+
return a.category.localeCompare(b.category);
78+
}
79+
return a.name.localeCompare(b.name);
80+
});
81+
}
82+
83+
function generateReadmeToolsList(tools: ToolInfo[]): string {
84+
const sections: string[] = [];
85+
86+
// Group tools by category
87+
const toolsByCategory: Record<string, ToolInfo[]> = {};
88+
for (const tool of tools) {
89+
if (!toolsByCategory[tool.category]) {
90+
toolsByCategory[tool.category] = [];
91+
}
92+
const categoryTools = toolsByCategory[tool.category];
93+
if (categoryTools) {
94+
categoryTools.push(tool);
95+
}
96+
}
97+
98+
// Generate sections for each category
99+
const categoryTitles: Record<string, string> = {
100+
atlas: "MongoDB Atlas Tools",
101+
"atlas-local": "MongoDB Atlas Local Tools",
102+
mongodb: "MongoDB Database Tools",
103+
};
104+
105+
const categoryOrder = ["atlas", "atlas-local", "mongodb"];
106+
107+
for (const category of categoryOrder) {
108+
if (!toolsByCategory[category]) continue;
109+
110+
sections.push(`#### ${categoryTitles[category]}\n`);
111+
112+
for (const tool of toolsByCategory[category]) {
113+
sections.push(`- \`${tool.name}\` - ${tool.description}`);
114+
}
115+
116+
// Add note for Atlas tools
117+
if (category === "atlas") {
118+
sections.push(
119+
"\nNOTE: atlas tools are only available when you set credentials on [configuration](#configuration) section.\n"
120+
);
121+
} else {
122+
sections.push("");
123+
}
124+
}
125+
126+
return sections.join("\n");
127+
}
128+
129+
function updateReadmeToolsList(tools: ToolInfo[]): void {
130+
const readmePath = join(__dirname, "..", "..", "README.md");
131+
let content = readFileSync(readmePath, "utf-8");
132+
133+
const newToolsList = generateReadmeToolsList(tools);
134+
135+
// Find and replace the tools list section
136+
// Match from "### Tool List" to the next "## " section
137+
const toolsRegex = /### Tool List\n\n([\s\S]*?)\n\n## 📄 Supported Resources/;
138+
const replacement = `### Tool List\n\n${newToolsList}\n## 📄 Supported Resources`;
139+
140+
content = content.replace(toolsRegex, replacement);
141+
142+
writeFileSync(readmePath, content, "utf-8");
143+
console.log("✓ Updated README.md tools list");
144+
}
145+
146+
export function generateToolDocumentation(): void {
147+
const toolInfo = extractToolInformation();
148+
updateReadmeToolsList(toolInfo);
149+
}

scripts/generate/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env tsx
2+
3+
/**
4+
* Main script that generates all documentation and configuration files:
5+
* - CLI arguments and configuration tables
6+
* - Tool documentation
7+
*/
8+
9+
import { generateArguments } from "./generateArguments.js";
10+
import { generateToolDocumentation } from "./generateToolDocumentation.js";
11+
12+
function main(): void {
13+
console.log("Generating arguments and configuration...");
14+
generateArguments();
15+
16+
console.log("\nGenerating tool documentation...");
17+
generateToolDocumentation();
18+
19+
console.log("\n✅ All documentation generated successfully!");
20+
}
21+
22+
main();

tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"declarationMap": true,
2121
"paths": {
2222
"mongodb-connection-string-url": [
23-
"./node_modules/mongodb-connection-string-url/lib/index.d.ts"
23+
"./node_modules/mongodb-connection-string-url/lib/index.js",
24+
"./node_modules/mongodb-connection-string-url/lib/index.d.js"
2425
],
2526
"ts-levenshtein": ["./node_modules/ts-levenshtein/dist/index.d.mts"]
2627
}

0 commit comments

Comments
 (0)