mongodb_create_database
Create a new database in MongoDB for storing and organizing data through the MCP Mac Apps Server.
Instructions
Создает новую базу данных в MongoDB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных |
Implementation Reference
- src/index.ts:621-642 (handler)The main handler function that executes the mongodb_create_database tool. It connects to MongoDB, selects the database, creates and drops a temporary collection to materialize the database, and returns a success message.private async mongodbCreateDatabase(databaseName: string) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); // Создаем коллекцию, чтобы база данных реально создалась await db.createCollection("_temp"); await db.collection("_temp").drop(); return { content: [ { type: "text", text: `База данных "${databaseName}" успешно создана`, }, ], }; } catch (error) { throw new Error( `Ошибка создания базы данных: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); }
- src/index.ts:158-170 (schema)Input schema definition for the tool, defining the required 'databaseName' parameter as a string.name: "mongodb_create_database", description: "Создает новую базу данных в MongoDB", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, }, required: ["databaseName"], }, },
- src/index.ts:338-339 (registration)Tool dispatch/registration in the switch statement handling CallToolRequest, mapping the tool name to its handler function.case "mongodb_create_database": return await this.mongodbCreateDatabase(args?.databaseName as string);
- src/index.ts:615-619 (helper)Helper method to establish a MongoDB client connection, used by all MongoDB-related tools including the create database handler.private async getMongoClient(): Promise<MongoClient> { const client = new MongoClient(MONGODB_URI); await client.connect(); return client; }
- src/server.py:415-427 (handler)Alternative Python implementation of the handler (note: dispatch is commented out in handle_request).def mongodb_create_database(database_name: str) -> str: """Creates database in MongoDB""" client = MongoClient(MONGODB_URI) try: db = client[database_name] # Create temporary collection so database is actually created db.create_collection("_temp") db["_temp"].drop() return f'Database "{database_name}" successfully created' except Exception as e: raise Exception(f"Error creating database: {str(e)}") finally: client.close()