delete_memory
Permanently remove a memory node and all its connections from the Neo4j graph database. Use this tool to delete specific agent memories and their relationships.
Instructions
Delete a memory and all its connections (use with caution - this permanently removes the memory and all its connections)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | ID of the memory to delete |
Implementation Reference
- src/handlers/index.ts:265-277 (handler)Handler logic for the 'delete_memory' tool. Validates arguments using isDeleteMemoryArgs, deletes the node using Neo4j client, and returns the result.case 'delete_memory': { if (!isDeleteMemoryArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid delete_memory arguments'); } const result = await neo4j.deleteNode(args.nodeId); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], };
- src/tools/definitions.ts:138-150 (schema)MCP tool definition and input schema for 'delete_memory', including name, description, and JSON schema for parameters.name: 'delete_memory', description: 'Delete a memory and all its connections (use with caution - this permanently removes the memory and all its connections)', inputSchema: { type: 'object', properties: { nodeId: { type: 'number', description: 'ID of the memory to delete', }, }, required: ['nodeId'], }, },
- src/server.ts:39-41 (registration)Registration of tools list handler in MCP server, which returns the tools array including 'delete_memory'.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools, }));
- src/types.ts:41-102 (schema)TypeScript interface and type guard for DeleteMemoryArgs used in handler validation.export interface DeleteMemoryArgs { nodeId: number; } export interface DeleteConnectionArgs { fromMemoryId: number; toMemoryId: number; type: string; } export interface ListMemoryLabelsArgs { // No arguments needed for this tool } export function isCreateMemoryArgs(args: unknown): args is CreateMemoryArgs { return typeof args === 'object' && args !== null && typeof (args as CreateMemoryArgs).label === 'string' && typeof (args as CreateMemoryArgs).properties === 'object'; } export function isSearchMemoriesArgs(args: unknown): args is SearchMemoriesArgs { if (typeof args !== 'object' || args === null) return false; const searchArgs = args as SearchMemoriesArgs; if (searchArgs.query !== undefined && typeof searchArgs.query !== 'string') return false; if (searchArgs.since_date !== undefined && typeof searchArgs.since_date !== 'string') return false; return true; } export function isCreateConnectionArgs(args: unknown): args is CreateConnectionArgs { return ( typeof args === 'object' && args !== null && typeof (args as CreateConnectionArgs).fromMemoryId === 'number' && typeof (args as CreateConnectionArgs).toMemoryId === 'number' && typeof (args as CreateConnectionArgs).type === 'string' ); } export function isUpdateMemoryArgs(args: unknown): args is UpdateMemoryArgs { return ( typeof args === 'object' && args !== null && typeof (args as UpdateMemoryArgs).nodeId === 'number' && typeof (args as UpdateMemoryArgs).properties === 'object' ); } export function isUpdateConnectionArgs(args: unknown): args is UpdateConnectionArgs { return ( typeof args === 'object' && args !== null && typeof (args as UpdateConnectionArgs).fromMemoryId === 'number' && typeof (args as UpdateConnectionArgs).toMemoryId === 'number' && typeof (args as UpdateConnectionArgs).type === 'string' && typeof (args as UpdateConnectionArgs).properties === 'object' ); } export function isDeleteMemoryArgs(args: unknown): args is DeleteMemoryArgs { return ( typeof args === 'object' && args !== null && typeof (args as DeleteMemoryArgs).nodeId === 'number' );
- src/neo4j-client.ts:116-126 (helper)Neo4jClient.deleteNode method: executes Cypher query to detach delete the node by ID and returns deletion count.async deleteNode(nodeId: number): Promise<any> { const result = await this.executeQuery( `MATCH (n) WHERE id(n) = $nodeId DETACH DELETE n RETURN count(n) as deletedCount`, { nodeId: neo4j.int(nodeId), } ); return result[0]; }