Skip to main content
Glama
TrueOleg

MCP Mac Apps Server

by TrueOleg

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
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных

Implementation Reference

  • 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()
  • 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();
      }
  • 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"],
        },
    },
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TrueOleg/MCP-expirements'

If you have feedback or need assistance with the MCP directory API, please join our Discord server