Skip to main content
Glama

delete_memory

Remove outdated or irrelevant memories from your knowledge repository with built-in confirmation safeguards. Protects against accidental data loss while maintaining a clean, focused memory collection.

Instructions

Safely remove outdated or irrelevant memories from your knowledge repository with built-in confirmation safeguards. Maintain a clean, focused memory collection while protecting against accidental loss of valuable information through required confirmation protocols.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confirmYesMust be set to true to confirm deletion (safety measure)
idYesThe unique identifier of the memory to delete
workingDirectoryYesThe full absolute path to the working directory where data is stored. MUST be an absolute path, never relative. Windows: "C:\Users\username\project" or "D:\projects\my-app". Unix/Linux/macOS: "/home/username/project" or "/Users/username/project". Do NOT use: ".", "..", "~", "./folder", "../folder" or any relative paths. Ensure the path exists and is accessible before calling this tool. NOTE: When server is started with --claude flag, this parameter is ignored and a global user directory is used instead.

Implementation Reference

  • The handler function executes the delete_memory tool logic: validates ID and confirmation, retrieves memory details, deletes via storage, and returns success/error messages with details.
    handler: async ({ id, confirm }: { id: string; confirm: boolean }) => { try { // Validate inputs if (!id || id.trim().length === 0) { return { content: [{ type: 'text' as const, text: 'Error: Memory ID is required.' }], isError: true }; } if (!confirm) { return { content: [{ type: 'text' as const, text: `⚠️ Deletion not confirmed. **Memory ID:** ${id} To delete this memory, you must set the 'confirm' parameter to true. This action cannot be undone. **Warning:** Deleting a memory will permanently remove it from the vector database.` }], isError: true }; } // Get the memory first to show what's being deleted const memory = await storage.getMemory(id.trim()); if (!memory) { return { content: [{ type: 'text' as const, text: `❌ Memory not found. **Memory ID:** ${id} The memory with this ID does not exist or may have already been deleted.` }], isError: true }; } // Delete the memory const deleted = await storage.deleteMemory(id.trim()); if (!deleted) { return { content: [{ type: 'text' as const, text: `❌ Failed to delete memory. **Memory ID:** ${id} The memory could not be deleted. Please try again.` }], isError: true }; } return { content: [{ type: 'text' as const, text: `✅ Memory deleted successfully! **Deleted Memory Details:** • **ID:** ${memory.id} • **Title:** ${memory.title} • **Content:** ${memory.content.substring(0, 200)}${memory.content.length > 200 ? '...' : ''} • **Category:** ${memory.category || 'Not specified'} • **Created:** ${new Date(memory.createdAt).toLocaleString()} The memory has been permanently removed from storage and cannot be recovered.` }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Error deleting memory: ${error instanceof Error ? error.message : 'Unknown error'}` }], isError: true }; } }
  • Zod input schema defining parameters: id (string) and confirm (boolean).
    inputSchema: { id: z.string(), confirm: z.boolean() },
  • Factory function that creates and configures the delete_memory MCP tool, setting name, description, schema, and handler.
    export function createDeleteMemoryTool(storage: MemoryStorage) { return { name: 'delete_memory', description: 'Delete a memory by ID (requires confirmation)', inputSchema: { id: z.string(), confirm: z.boolean() }, handler: async ({ id, confirm }: { id: string; confirm: boolean }) => { try { // Validate inputs if (!id || id.trim().length === 0) { return { content: [{ type: 'text' as const, text: 'Error: Memory ID is required.' }], isError: true }; } if (!confirm) { return { content: [{ type: 'text' as const, text: `⚠️ Deletion not confirmed. **Memory ID:** ${id} To delete this memory, you must set the 'confirm' parameter to true. This action cannot be undone. **Warning:** Deleting a memory will permanently remove it from the vector database.` }], isError: true }; } // Get the memory first to show what's being deleted const memory = await storage.getMemory(id.trim()); if (!memory) { return { content: [{ type: 'text' as const, text: `❌ Memory not found. **Memory ID:** ${id} The memory with this ID does not exist or may have already been deleted.` }], isError: true }; } // Delete the memory const deleted = await storage.deleteMemory(id.trim()); if (!deleted) { return { content: [{ type: 'text' as const, text: `❌ Failed to delete memory. **Memory ID:** ${id} The memory could not be deleted. Please try again.` }], isError: true }; } return { content: [{ type: 'text' as const, text: `✅ Memory deleted successfully! **Deleted Memory Details:** • **ID:** ${memory.id} • **Title:** ${memory.title} • **Content:** ${memory.content.substring(0, 200)}${memory.content.length > 200 ? '...' : ''} • **Category:** ${memory.category || 'Not specified'} • **Created:** ${new Date(memory.createdAt).toLocaleString()} The memory has been permanently removed from storage and cannot be recovered.` }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Error deleting memory: ${error instanceof Error ? error.message : 'Unknown error'}` }], isError: true }; } } }; }
  • Underlying storage implementation for deleting a memory by ID: locates the JSON file and unlinks it from the filesystem.
    async deleteMemory(id: string): Promise<boolean> { const filePath = await this.findMemoryFileById(id); if (!filePath) { return false; } try { await fs.unlink(filePath); return true; } catch (error) { return false; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pimzino/agentic-tools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server