Skip to main content
Glama

delete_memory

Remove a specific memory entry by ID from the mem0 Memory System, ensuring precise data management and user control over stored information.

Instructions

Deletes a specific memory from Mem0 by ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agentIdNoOptional agent ID associated with the memory (for cloud API).
memoryIdYesThe unique ID of the memory to delete.
sessionIdNoOptional session ID associated with the memory.
userIdYesUser ID associated with the memory.

Implementation Reference

  • The primary handler function for the 'delete_memory' tool. It validates inputs, determines the storage mode (cloud, Supabase, or local), and calls the appropriate client's deleteMemory method or falls back to direct API calls or internal vectorstore deletion.
    private async handleDeleteMemory(args: Mem0DeleteToolArgs): Promise<any> { const { memoryId, userId, agentId, appId, projectId, orgId } = args; if (!memoryId) { throw new McpError(ErrorCode.InvalidParams, "Missing required argument: memoryId"); } // Use DEFAULT_USER_ID as fallback if userId is not provided const finalUserId = userId || process.env.DEFAULT_USER_ID; if (!finalUserId) { throw new McpError(ErrorCode.InvalidParams, "Missing required argument: userId (and no DEFAULT_USER_ID environment variable set)"); } if (this.isCloudMode && this.cloudClient) { try { // Get all parameters - parameter takes precedence over environment const finalAppId = appId || process.env.DEFAULT_APP_ID; const finalAgentId = agentId || process.env.DEFAULT_AGENT_ID; const finalProjectId = projectId || process.env.DEFAULT_PROJECT_ID; const finalOrgId = orgId || process.env.DEFAULT_ORG_ID; // Cloud API options - using snake_case for API parameters // Note: Delete memory uses v1 API, no version parameter needed const options: any = { memory_id: memoryId, user_id: finalUserId }; // Add all parameters if available (using snake_case) if (finalAppId) options.app_id = finalAppId; if (finalAgentId) options.agent_id = finalAgentId; if (finalProjectId) options.project_id = finalProjectId; if (finalOrgId) options.org_id = finalOrgId; // Try to use the API's deleteMemory method through the client try { // @ts-ignore - We'll try to access this method even if TypeScript doesn't recognize it await this.cloudClient.deleteMemory(memoryId); } catch (innerError) { // If that fails, try to use a generic request method await fetch(`https://api.mem0.ai/v1/memories/${memoryId}/`, { method: 'DELETE', headers: { 'Authorization': `Token ${process.env.MEM0_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify(options) }); } return { content: [{ type: "text", text: `Memory ${memoryId} deleted successfully` }], }; } catch (error: any) { throw new McpError(ErrorCode.InternalError, `Error deleting memory: ${error.message}`); } } else if (this.isSupabaseMode && this.supabaseClient) { try { // For Supabase storage, try to use the deleteMemory method try { // @ts-ignore - We'll try to access this method even if TypeScript doesn't recognize it await this.supabaseClient.deleteMemory(memoryId); } catch (innerError) { // If direct method fails, try to access through any internal methods // @ts-ignore - Accessing potentially private properties if (this.supabaseClient._vectorstore && typeof this.supabaseClient._vectorstore.delete === 'function') { // @ts-ignore await this.supabaseClient._vectorstore.delete({ ids: [memoryId] }); } else { throw new Error("Supabase client does not support memory deletion"); } } return { content: [{ type: "text", text: `Memory ${memoryId} deleted successfully` }], }; } catch (error: any) { throw new McpError(ErrorCode.InternalError, `Error deleting memory: ${error.message || "Supabase client does not support memory deletion"}`); } } else if (this.localClient) { try { // For local storage, we need to find a way to delete the memory // Since we don't have direct access to deleteMemory, we'll try to access it indirectly try { // @ts-ignore - We'll try to access this method even if TypeScript doesn't recognize it await this.localClient.deleteMemory(memoryId); } catch (innerError) { // @ts-ignore - Accessing potentially private properties if (this.localClient._vectorstore && typeof this.localClient._vectorstore.delete === 'function') { // @ts-ignore await this.localClient._vectorstore.delete({ ids: [memoryId] }); } else { throw new Error("Local client does not support memory deletion"); } } return { content: [{ type: "text", text: `Memory ${memoryId} deleted successfully` }], }; } catch (error: any) { throw new McpError(ErrorCode.InternalError, `Error deleting memory: ${error.message || "Local client does not support memory deletion"}`); } } else { throw new McpError(ErrorCode.InternalError, "No memory client is available"); } }
  • src/index.ts:401-434 (registration)
    Tool registration in the ListTools handler, including name, description, and input schema definition.
    { name: "delete_memory", description: "Deletes a specific memory by ID from Mem0.", inputSchema: { type: "object", properties: { memoryId: { type: "string", description: "The unique ID of the memory to delete.", }, userId: { type: "string", description: "User ID associated with the memory. If not provided, uses DEFAULT_USER_ID environment variable.", }, agentId: { type: "string", description: "Optional agent ID - identifies the LLM/agent making the tool call. If not provided, uses DEFAULT_AGENT_ID environment variable.", }, appId: { type: "string", description: "Optional app ID - application identifier (legacy parameter). If not provided, uses DEFAULT_APP_ID environment variable.", }, projectId: { type: "string", description: "Optional project ID - for mem0 Pro plan project organization (e.g., proj_ABC123). If not provided, uses DEFAULT_PROJECT_ID environment variable.", }, orgId: { type: "string", description: "Optional organization ID - for mem0 organization-level management. If not provided, uses DEFAULT_ORG_ID environment variable.", }, }, required: ["memoryId"], }, },
  • TypeScript interface defining the structure of arguments expected by the delete_memory handler.
    interface Mem0DeleteToolArgs { memoryId: string; userId?: string; agentId?: string; // The LLM/agent making the tool call appId?: string; // Application identifier (legacy parameter) projectId?: string; // Project identifier (for mem0 Pro plan project organization) orgId?: string; // Organization identifier (for mem0 organization-level management) }
  • src/index.ts:455-457 (registration)
    Dispatcher in the CallToolRequest handler that routes 'delete_memory' calls to the handleDeleteMemory function.
    } else if (name === "delete_memory") { const toolArgs = args as unknown as Mem0DeleteToolArgs; return await this.handleDeleteMemory(toolArgs);

Other Tools

Related Tools

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/pinkpixel-dev/mem0-mcp'

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