Skip to main content
Glama

mongodb_create_database

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

Instructions

Создает новую базу данных в MongoDB

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных

Implementation Reference

  • 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(); } }
  • 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);
  • 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()
  • 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"], }, },

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