Remove an edge between two memories
memory_unlinkRemove a specific edge between two memories by providing the exact from_id, to_id, and edge_type triple. Use to retract incorrect links without deleting the full memory records.
Instructions
Remove a previously created edge — pass the exact (from_id, to_id, edge_type) triple used at creation time. No wildcards. Idempotent. Use to retract incorrect links. To retract a whole memory, prefer memory_delete (keeps audit trail).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_id | Yes | Source memory id of the edge to remove. | |
| to_id | Yes | Target memory id of the edge to remove. | |
| edge_type | Yes | Edge type that was used when the edge was created. Must match exactly. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | `Edge removed: <from> -[<edge_type>]-> <to>` on success, or `Edge not found.` when the triple does not exist. |
Implementation Reference
- src/tools/memory-unlink.ts:11-20 (handler)Core handler function that calls edgesRepo.unlink() to remove a typed edge between two memories, returning a success or 'not found' message.
export async function handleMemoryUnlink( edgesRepo: EdgesRepo, params: MemoryUnlinkParams ): Promise<string> { const removed = edgesRepo.unlink(params.from_id, params.to_id, params.edge_type); if (!removed) { return `No edge found: ${params.from_id} --[${params.edge_type}]--> ${params.to_id}`; } return `Unlinked ${params.from_id} --[${params.edge_type}]--> ${params.to_id}`; } - src/tools/memory-unlink.ts:5-9 (schema)Input parameters interface for the memory_unlink tool: requires from_id, to_id, and edge_type.
export interface MemoryUnlinkParams { from_id: string; to_id: string; edge_type: EdgeType; } - src/index.ts:704-729 (registration)MCP server registration of the 'memory_unlink' tool with input schema (from_id, to_id, edge_type), annotations, output schema, and handler binding.
server.registerTool( "memory_unlink", { title: "Remove an edge between two memories", description: [ "Remove a previously created edge — pass the exact `(from_id, to_id, edge_type)` triple used at creation time. No wildcards. Idempotent.", "Use to retract incorrect links. To retract a whole memory, prefer `memory_delete` (keeps audit trail).", ].join(" "), inputSchema: { from_id: z.string().min(1).describe("Source memory id of the edge to remove."), to_id: z.string().min(1).describe("Target memory id of the edge to remove."), edge_type: edgeTypeEnum.describe("Edge type that was used when the edge was created. Must match exactly."), }, annotations: { title: "Remove an edge between two memories", readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false, }, outputSchema: { message: z.string().describe("`Edge removed: <from> -[<edge_type>]-> <to>` on success, or `Edge not found.` when the triple does not exist."), }, }, async (params) => textResult(await handleMemoryUnlink(edgesRepo, params)) ); - src/db/edges.ts:46-51 (helper)Database-level unlink method on EdgesRepo that executes a DELETE query on memory_edges table for the exact (from_id, to_id, edge_type) triple, returning whether any row was deleted.
unlink(fromId: string, toId: string, type: EdgeType): boolean { const result = this.db.prepare(` DELETE FROM memory_edges WHERE from_id = ? AND to_id = ? AND edge_type = ? `).run(fromId, toId, type); return result.changes > 0; }