drop-collection
Remove a MongoDB collection or view from a database, including all associated indexes, to clean up unused data structures.
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 |
|---|---|---|---|
| database | Yes | Database name | |
| collection | Yes | Collection name |
Implementation Reference
- The execute method that performs the drop collection operation using the MongoDB service provider and returns a textual result indicating success or failure.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", }, ], }; }
- Zod schema defining the required 'database' and 'collection' string parameters used by the drop-collection tool via argsShape spread.export const DbOperationArgs = { database: z.string().describe("Database name"), collection: z.string().describe("Collection name"), };
- src/tools/mongodb/tools.ts:22-43 (registration)The MongoDbTools array includes DropCollectionTool (imported at line 17), which is iterated over in src/server.ts to instantiate and register each tool with the MCP server.export const MongoDbTools = [ ConnectTool, ListCollectionsTool, ListDatabasesTool, CollectionIndexesTool, CreateIndexTool, CollectionSchemaTool, FindTool, InsertManyTool, DeleteManyTool, CollectionStorageSizeTool, CountTool, DbStatsTool, AggregateTool, UpdateManyTool, RenameCollectionTool, DropDatabaseTool, DropCollectionTool, ExplainTool, CreateCollectionTool, LogsTool, ];
- Tool metadata: name, description, input argsShape (spreading DbOperationArgs schema), and operation type, defining the tool's interface.protected name = "drop-collection"; protected description = "Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection."; protected argsShape = { ...DbOperationArgs, }; protected operationType: OperationType = "delete";