Skip to main content
Glama
officialpraise

MongoDB MCP Server

create-collection

Create a new MongoDB collection in a specified database. Automatically creates the database if it doesn't exist.

Instructions

Creates a new collection in a database. If the database doesn't exist, it will be created automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name
collectionYesCollection name

Implementation Reference

  • The execute method implements the core logic of the 'create-collection' tool, connecting to MongoDB if necessary and calling createCollection on the provider.
    protected async execute({ collection, database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
        const provider = await this.ensureConnected();
        await provider.createCollection(database, collection);
    
        return {
            content: [
                {
                    type: "text",
                    text: `Collection "${collection}" created in database "${database}".`,
                },
            ],
        };
    }
  • Zod schema defining the required input parameters (database and collection) for the create-collection tool, referenced via argsShape.
    export const DbOperationArgs = {
        database: z.string().describe("Database name"),
        collection: z.string().describe("Collection name"),
    };
  • Includes CreateCollectionTool in the MongoDbTools export array, enabling its instantiation and registration in the MCP server via server.ts.
    CreateCollectionTool,
  • src/server.ts:142-144 (registration)
    Instantiates each tool from MongoDbTools (including create-collection) and calls its register method on the MCP server.
    for (const tool of [...AtlasTools, ...MongoDbTools]) {
        new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer);
    }
  • Declares the tool name as 'create-collection', used during registration for MCP tool listing.
    protected name = "create-collection";

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/officialpraise/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server