delete_entities
Remove specified entities and their related connections from the knowledge graph stored in the MCP DuckDB Memory Server, ensuring efficient data management.
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)Implements the logic to delete specified entities, first removing associated observations and relations from the DuckDB tables, then the entities themselves, and finally updating 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:90-104 (registration)Registers the 'delete_entities' MCP tool, specifying name, description, input schema, and handler that delegates to knowledgeGraphManager.deleteEntities."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-97 (schema)Zod input schema for the delete_entities tool: array of strings for entity names.entityNames: z .array(z.string()) .describe("An array of entity names to delete"), }, async ({ entityNames }) => {
- src/types.ts:59-59 (schema)Type signature for the deleteEntities method in the KnowledgeGraphManagerInterface.deleteEntities(entityNames: string[]): Promise<void>;