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
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name | |
| collection | Yes | Collection 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"), }; - src/tools/mongodb/tools.ts:41-41 (registration)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";