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
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных | |
| collectionName | Yes | Имя коллекции |
Implementation Reference
- src/index.ts:671-693 (handler)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(); }
- src/index.ts:179-195 (schema)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 );
- src/server.py:451-464 (handler)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()
- src/server.py:166-182 (schema)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"], },