Skip to main content
Glama

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
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных

Implementation Reference

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

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