list-databases
Retrieve a list of all available databases for a MongoDB connection using this tool, enabling efficient management and access to database resources.
Instructions
List all databases for a MongoDB connection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/mongodb/metadata/listDatabases.ts:7-11 (registration)Tool class definition including the unique name 'list-databases', description, input schema (empty), and operation type.export class ListDatabasesTool extends MongoDBToolBase { public name = "list-databases"; protected description = "List all databases for a MongoDB connection"; protected argsShape = {}; static operationType: OperationType = "metadata";
- The handler function that executes the tool: connects to MongoDB, fetches the list of databases, and returns formatted content with database names and sizes.protected async execute(): Promise<CallToolResult> { const provider = await this.ensureConnected(); const dbs = (await provider.listDatabases("")).databases as { name: string; sizeOnDisk: bson.Long }[]; return { content: formatUntrustedData( `Found ${dbs.length} databases`, ...dbs.map((db) => `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`) ), }; }
- src/tools/mongodb/tools.ts:4-4 (registration)Re-exports ListDatabasesTool as part of the MongoDB tools module, enabling its inclusion in the overall tools registry via src/tools/index.ts.export { ListDatabasesTool } from "./metadata/listDatabases.js";
- src/tools/index.ts:7-8 (registration)Registers all MongoDB tools, including ListDatabasesTool (via MongoDbTools), into the central AllTools array used for tool registration in the MCP server.export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools,