mongodb_list_collections
Retrieve all collections from a specified MongoDB database to view available data structures and manage database organization.
Instructions
Получает список коллекций в указанной базе данных
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных |
Implementation Reference
- src/server.py:467-480 (handler)Python implementation of the mongodb_list_collections tool handler using pymongo to list collections in a specified database.def mongodb_list_collections(database_name: str) -> str: """Gets list of collections""" client = MongoClient(MONGODB_URI) try: db = client[database_name] collections = list(db.list_collection_names()) result = f'Collections in database "{database_name}":\n' + ( "\n".join(collections) if collections else "No collections found" ) return result except Exception as e: raise Exception(f"Error getting list of collections: {str(e)}") finally: client.close()
- src/index.ts:696-721 (handler)TypeScript implementation of the mongodbListCollections tool handler using MongoDB Node.js driver to list collections in a specified database.private async mongodbListCollections(databaseName: string) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); const collections = await db.listCollections().toArray(); const collectionNames = collections.map((col) => col.name); return { content: [ { type: "text", text: `Коллекции в базе данных "${databaseName}":\n${ collectionNames.length > 0 ? collectionNames.join("\n") : "Коллекции не найдены" }`, }, ], }; } catch (error) { throw new Error( `Ошибка получения списка коллекций: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); }
- src/server.py:184-197 (schema)Input schema definition for the mongodb_list_collections tool in the Python MCP server.{ "name": "mongodb_list_collections", "description": "Gets list of collections in specified database", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, }, "required": ["databaseName"], }, },
- src/index.ts:197-209 (schema)Input schema definition for the mongodb_list_collections tool in the TypeScript MCP server.{ name: "mongodb_list_collections", description: "Получает список коллекций в указанной базе данных", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, }, required: ["databaseName"], },
- src/index.ts:350-351 (registration)Registration of the mongodb_list_collections handler in the tool call switch statement in TypeScript MCP server.case "mongodb_list_collections": return await this.mongodbListCollections(args?.databaseName as string);