Skip to main content
Glama
TrueOleg

MCP Mac Apps Server

by TrueOleg

mongodb_create_collection

Create a new collection in a specified MongoDB database to organize and store data for your application.

Instructions

Создает новую коллекцию в указанной базе данных

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных
collectionNameYesИмя коллекции

Implementation Reference

  • The handler function that implements the core logic for the 'mongodb_create_collection' tool. It connects to MongoDB, creates the specified collection in the given database, and returns a success message or throws an error.
    private async mongodbCreateCollection(
      databaseName: string,
      collectionName: string
    ) {
      const client = await this.getMongoClient();
      try {
        const db = client.db(databaseName);
        await db.createCollection(collectionName);
        return {
          content: [
            {
              type: "text",
              text: `Коллекция "${collectionName}" успешно создана в базе данных "${databaseName}"`,
            },
          ],
        };
      } catch (error) {
        throw new Error(
          `Ошибка создания коллекции: ${error instanceof Error ? error.message : String(error)}`
        );
      } finally {
        await client.close();
      }
  • The handler function that implements the core logic for the 'mongodb_create_collection' tool. It connects to MongoDB, creates the specified collection, and returns a success message.
    def mongodb_create_collection(database_name: str, collection_name: str) -> str:
        """Creates collection in database"""
        client = MongoClient(MONGODB_URI)
        try:
            db = client[database_name]
            db.create_collection(collection_name)
            return (
                f'Collection "{collection_name}" successfully created '
                f'in database "{database_name}"'
            )
        except Exception as e:
            raise Exception(f"Error creating collection: {str(e)}")
        finally:
            client.close()
  • The input schema definition for the 'mongodb_create_collection' tool, used in tools/list response for registration.
    name: "mongodb_create_collection",
    description: "Создает новую коллекцию в указанной базе данных",
    inputSchema: {
      type: "object",
      properties: {
        databaseName: {
          type: "string",
          description: "Имя базы данных",
        },
        collectionName: {
          type: "string",
          description: "Имя коллекции",
        },
      },
      required: ["databaseName", "collectionName"],
    },
  • The input schema definition for the 'mongodb_create_collection' tool, returned in the tools/list endpoint.
        "name": "mongodb_create_collection",
        "description": "Creates new collection in specified database",
        "inputSchema": {
            "type": "object",
            "properties": {
                "databaseName": {
                    "type": "string",
                    "description": "Database name",
                },
                "collectionName": {
                    "type": "string",
                    "description": "Collection name",
                },
            },
            "required": ["databaseName", "collectionName"],
        },
    },
  • src/index.ts:344-348 (registration)
    The dispatch case in the tool call handler that routes to the mongodbCreateCollection method.
    case "mongodb_create_collection":
      return await this.mongodbCreateCollection(
        args?.databaseName as string,
        args?.collectionName 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