DeleteCollection
Remove a named collection from Astra DB using the MCP Server. Specify the collection name to delete it and manage database storage effectively.
Instructions
Delete a collection from the database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionName | Yes | Name of the collection to delete |
Input Schema (JSON Schema)
{
"properties": {
"collectionName": {
"description": "Name of the collection to delete",
"type": "string"
}
},
"required": [
"collectionName"
],
"type": "object"
}
Implementation Reference
- tools/DeleteCollection.ts:17-40 (handler)The main handler function that executes the deletion of a collection using the database's dropCollection method if available, returning success or error messages.export async function DeleteCollection(params: { collectionName: string }) { const { collectionName } = params; try { // Try to use dropCollection if available if (typeof db.dropCollection === 'function') { await db.dropCollection(collectionName); } else { // If dropCollection is not available, log a warning console.warn(`No dropCollection method available for collection '${collectionName}'`); } return { success: true, message: `Collection '${collectionName}' deleted successfully`, }; } catch (error) { console.error(`Error deleting collection '${collectionName}':`, error); return { success: false, message: `Failed to delete collection '${collectionName}'`, }; } }
- tools.ts:103-116 (schema)Defines the input schema and metadata for the DeleteCollection tool, specifying that 'collectionName' is a required string parameter.{ name: "DeleteCollection", description: "Delete a collection from the database", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection to delete", }, }, required: ["collectionName"], }, },
- index.ts:127-138 (registration)Registers the tool execution in the MCP server's CallToolRequestSchema handler by importing and calling DeleteCollection in the switch statement.case "DeleteCollection": const deleteResult = await DeleteCollection({ collectionName: args.collectionName as string, }); return { content: [ { type: "text", text: deleteResult.message, }, ], };