mongodb_list_databases
Retrieve a list of all databases in MongoDB to manage data storage and organization for macOS application control.
Instructions
Получает список всех баз данных в MongoDB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:645-669 (handler)The main handler function that executes the tool logic: connects to MongoDB using MongoClient, lists all databases via admin().listDatabases(), filters out system databases, and returns a formatted text response.private async mongodbListDatabases() { const client = await this.getMongoClient(); try { const adminDb = client.db().admin(); const { databases } = await adminDb.listDatabases(); const dbNames = databases .map((db) => db.name) .filter((name) => !["admin", "config", "local"].includes(name)); return { content: [ { type: "text", text: `Базы данных:\n${dbNames.length > 0 ? dbNames.join("\n") : "Базы данных не найдены"}`, }, ], }; } catch (error) { throw new Error( `Ошибка получения списка баз данных: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); } }
- src/index.ts:172-178 (schema)The tool's schema definition in the list of tools, specifying the name, description, and empty input schema (no parameters required).name: "mongodb_list_databases", description: "Получает список всех баз данных в MongoDB", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:341-342 (registration)Registration in the tool call handler switch statement, mapping the tool name to the handler function.case "mongodb_list_databases": return await this.mongodbListDatabases();
- src/index.ts:615-619 (helper)Helper function to create and connect a MongoClient instance, reused by all MongoDB tools.private async getMongoClient(): Promise<MongoClient> { const client = new MongoClient(MONGODB_URI); await client.connect(); return client; }