delete_entities
Remove entities and their connections from a knowledge graph to maintain data accuracy and manage stored information.
Instructions
Delete multiple entities and their associated relations from the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityNames | Yes | An array of entity names to delete |
Implementation Reference
- src/manager.ts:413-457 (handler)The core handler function that deletes the specified entities from the database. It first deletes associated observations and relations (ignoring errors), then deletes the entities, and updates the Fuse.js search index.async deleteEntities(entityNames: string[]): Promise<void> { if (entityNames.length === 0) return; try { using conn = await this.getConn(); // Create placeholders const placeholders = entityNames.map(() => "?").join(","); // Delete related observations first try { await conn.execute( `DELETE FROM observations WHERE entityName IN (${placeholders})`, entityNames ); } catch (error: unknown) { this.logger.error("Error deleting observations", extractError(error)); // Ignore error and continue } // Delete related relations try { await conn.execute( `DELETE FROM relations WHERE from_entity IN (${placeholders}) OR to_entity IN (${placeholders})`, [...entityNames, ...entityNames] ); } catch (error: unknown) { this.logger.error("Error deleting relations", extractError(error)); // Ignore error and continue } // Delete entities await conn.execute( `DELETE FROM entities WHERE name IN (${placeholders})`, entityNames ); // Update Fuse.js index const allEntities = await this.getAllEntities(); this.fuse.setCollection(allEntities); } catch (error: unknown) { this.logger.error("Error deleting entities", extractError(error)); throw error; } }
- src/server.ts:89-103 (registration)Registers the 'delete_entities' tool with the MCP server, defining its description, input schema using Zod, and handler that delegates to KnowledgeGraphManager.server.tool( "delete_entities", "Delete multiple entities and their associated relations from the knowledge graph", { entityNames: z .array(z.string()) .describe("An array of entity names to delete"), }, async ({ entityNames }) => { await knowledgeGraphManager.deleteEntities(entityNames); return { content: [{ type: "text", text: "Entities deleted successfully" }], }; } );
- src/server.ts:93-96 (schema)Zod input schema for the tool, specifying an array of strings for entity names.entityNames: z .array(z.string()) .describe("An array of entity names to delete"), },
- src/types.ts:59-59 (schema)TypeScript interface definition for the deleteEntities method in KnowledgeGraphManagerInterface.deleteEntities(entityNames: string[]): Promise<void>;