Skip to main content
Glama

mongodb_create_collection

Create a new collection in a specified MongoDB database using the MCP Mac Apps Server. Define database and collection names to organize data storage.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function that connects to MongoDB, creates the specified collection in the given database, and returns a success message.
    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(); }
  • Input schema definition for the mongodb_create_collection tool, specifying databaseName and collectionName as required string parameters.
    { name: "mongodb_create_collection", description: "Создает новую коллекцию в указанной базе данных", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, collectionName: { type: "string", description: "Имя коллекции", }, }, required: ["databaseName", "collectionName"], },
  • src/index.ts:344-348 (registration)
    Registration and dispatch case in the tool call handler that invokes the mongodbCreateCollection method.
    case "mongodb_create_collection": return await this.mongodbCreateCollection( args?.databaseName as string, args?.collectionName as string );
  • Alternative Python implementation of the handler that creates a MongoDB collection (note: dispatch is commented out).
    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()
  • Input schema definition for the tool in the Python version.
    { "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"], },

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