drop-collection
Remove a MongoDB collection or view and its associated indexes from a specified database using MongoDB MCP Server.
Instructions
Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| database | Yes | Database name |
Implementation Reference
- The core handler function that connects to MongoDB if needed, drops the specified collection, and returns a success or failure message.protected async execute({ database, collection }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const provider = await this.ensureConnected(); const result = await provider.dropCollection(database, collection); return { content: [ { text: `${result ? "Successfully dropped" : "Failed to drop"} collection "${collection}" from database "${database}"`, type: "text", }, ], }; }
- Tool input schema definition, inheriting database and collection arguments from base DbOperationArgs.protected argsShape = { ...DbOperationArgs, };
- Zod schema defining required database and collection string arguments for DB operation tools.export const DbOperationArgs = { database: z.string().describe("Database name"), collection: z.string().describe("Collection name"), };
- src/tools/mongodb/tools.ts:22-43 (registration)Array of all MongoDB tools including DropCollectionTool, exported for higher-level registration.export const MongoDbTools = [ ConnectTool, ListCollectionsTool, ListDatabasesTool, CollectionIndexesTool, CreateIndexTool, CollectionSchemaTool, FindTool, InsertManyTool, DeleteManyTool, CollectionStorageSizeTool, CountTool, DbStatsTool, AggregateTool, UpdateManyTool, RenameCollectionTool, DropDatabaseTool, DropCollectionTool, ExplainTool, CreateCollectionTool, LogsTool, ];
- src/server.ts:142-144 (registration)Registers all tools from MongoDbTools (and AtlasTools) by instantiating each and calling their register method on the MCP server.for (const tool of [...AtlasTools, ...MongoDbTools]) { new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer); }