delete_relations
Remove specified relationships between entities from the knowledge graph to maintain data accuracy and relevance.
Instructions
Delete multiple relations from the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes | An array of relations to delete |
Implementation Reference
- src/server.ts:132-156 (registration)MCP tool registration for 'delete_relations', including input schema with Zod validation for relations array and an inline asynchronous handler that calls the manager's deleteRelations method and returns a success message.server.tool( "delete_relations", "Delete multiple relations from the knowledge graph", { relations: z .array( z.object({ from: z .string() .describe("The name of the entity where the relation starts"), to: z .string() .describe("The name of the entity where the relation ends"), relationType: z.string().describe("The type of the relation"), }) ) .describe("An array of relations to delete"), }, async ({ relations }) => { await knowledgeGraphManager.deleteRelations(relations); return { content: [{ type: "text", text: "Relations deleted successfully" }], }; } );
- src/manager.ts:501-524 (helper)Core helper function in KnowledgeGraphManager that implements the deletion of multiple relations from the SQLite 'relations' table using a transaction for atomicity, with rollback on error.async deleteRelations(relations: Relation[]): Promise<void> { using conn = await this.getConn(); try { // Begin transaction await conn.execute("BEGIN TRANSACTION"); // Delete each relation for (const relation of relations) { await conn.execute( "DELETE FROM relations WHERE from_entity = ? AND to_entity = ? AND relationType = ?", [relation.from, relation.to, relation.relationType] ); } // Commit transaction await conn.execute("COMMIT"); } catch (error: unknown) { // Rollback in case of error await conn.execute("ROLLBACK"); this.logger.error("Error deleting relations", extractError(error)); throw error; } }
- src/types.ts:55-64 (schema)TypeScript interface defining the deleteRelations method signature, specifying input as Relation[] and return Promise<void>.export type KnowledgeGraphManagerInterface = { createEntities(entities: Entity[]): Promise<Entity[]>; createRelations(relations: Relation[]): Promise<Relation[]>; addObservations(observations: Array<Observation>): Promise<Observation[]>; deleteEntities(entityNames: string[]): Promise<void>; deleteObservations(deletions: Array<Observation>): Promise<void>; deleteRelations(relations: Relation[]): Promise<void>; searchNodes(query: string): Promise<KnowledgeGraph>; openNodes(names: string[]): Promise<KnowledgeGraph>; };