mongodb_list_databases
Retrieve a list of all databases in MongoDB to manage data storage and organization within the MCP Mac Apps Server environment.
Instructions
Получает список всех баз данных в MongoDB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:645-669 (handler)Main handler function that connects to MongoDB, lists all databases via admin().listDatabases(), filters out system databases (admin, config, local), 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)Tool schema definition in the ListTools response, specifying 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)Dispatch/registration in the CallToolRequestHandler switch statement that routes the tool call to the mongodbListDatabases method.case "mongodb_list_databases": return await this.mongodbListDatabases();
- src/server.py:430-449 (handler)Python implementation of the handler function using pymongo to list databases, filtering system ones, returning formatted text. Note: dispatch case is commented out.def mongodb_list_databases() -> str: """Gets list of databases""" client = MongoClient(MONGODB_URI) try: admin_db = client.admin databases = admin_db.command("listDatabases") db_names = [ db["name"] for db in databases["databases"] if db["name"] not in ["admin", "config", "local"] ] result = "Databases:\n" + ( "\n".join(db_names) if db_names else "No databases found" ) return result except Exception as e: raise Exception(f"Error getting list of databases: {str(e)}") finally: client.close()
- src/index.ts:615-619 (helper)Helper method 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; }