drop-collection
Remove a MongoDB collection or view and its associated indexes from a specified database using the MCP Server, streamlining database management tasks.
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 main handler function that executes the drop-collection tool by calling the provider's dropCollection method and returning 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", }, ], }; }
- Zod schema defining the input arguments (database and collection) used by the drop-collection tool and other MongoDB operation tools.export const DbOperationArgs = { database: z.string().describe("Database name"), collection: z.string().describe("Collection name"), };
- Tool-specific input schema definition, which inherits from the shared DbOperationArgs.protected argsShape = { ...DbOperationArgs, };
- src/tools/mongodb/tools.ts:17-17 (registration)Registration of the DropCollectionTool by exporting it from the MongoDB tools module.export { DropCollectionTool } from "./delete/dropCollection.js";
- src/tools/index.ts:7-11 (registration)Includes the MongoDB tools module (containing drop-collection) in the central AllTools array for server registration.export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });