DeleteRecord
Remove a specific record from a collection in Astra DB by specifying the collection name and record ID using the MCP Server's tool for efficient data management.
Instructions
Delete a record from a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionName | Yes | Name of the collection containing the record | |
| recordId | Yes | ID of the record to delete |
Implementation Reference
- tools/DeleteRecord.ts:17-36 (handler)The main handler function that executes the deletion of a specific record from the given collection by ID using the database client.export async function DeleteRecord(params: { collectionName: string; recordId: string; }) { const { collectionName, recordId } = params; const collection = db.collection(collectionName); const result = await collection.deleteOne({ _id: recordId }); if (result.deletedCount === 0) { throw new Error( `Record with ID '${recordId}' not found in collection '${collectionName}'` ); } return { success: true, message: `Record '${recordId}' deleted successfully from collection '${collectionName}'`, }; }
- tools.ts:194-211 (schema)The JSON schema defining the input parameters for the DeleteRecord tool: collectionName and recordId.{ name: "DeleteRecord", description: "Delete a record from a collection", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection containing the record", }, recordId: { type: "string", description: "ID of the record to delete", }, }, required: ["collectionName", "recordId"], }, },
- index.ts:201-213 (registration)The switch case in the CallToolRequestSchema handler that registers and invokes the DeleteRecord tool during runtime.case "DeleteRecord": const deleteRecordResult = await DeleteRecord({ collectionName: args.collectionName as string, recordId: args.recordId as string, }); return { content: [ { type: "text", text: deleteRecordResult.message, }, ], };