mongodb_create_database
Create a new database in MongoDB to organize and store data collections for your application.
Instructions
Создает новую базу данных в MongoDB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных |
Implementation Reference
- src/index.ts:621-643 (handler)The handler function that executes the mongodb_create_database tool logic. Connects to MongoDB using getMongoClient, selects the database, creates and drops a temporary collection to materialize the database, returns success response.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)The input schema definition for the mongodb_create_database tool, specifying databaseName as a required string.name: "mongodb_create_database", description: "Создает новую базу данных в MongoDB", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, }, required: ["databaseName"], }, },
- src/index.ts:338-340 (registration)The switch case registration in the CallToolRequest handler that dispatches to the mongodbCreateDatabase method.case "mongodb_create_database": return await this.mongodbCreateDatabase(args?.databaseName as string);
- src/server.py:415-428 (handler)Python handler function for mongodb_create_database tool with identical logic to create database via temporary collection.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()
- src/server.py:145-157 (schema)The input schema for the tool in the Python server's tool list."name": "mongodb_create_database", "description": "Creates new database in MongoDB", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, }, "required": ["databaseName"], }, },