delete_entities
Remove entities and their relationships from the Memento MCP knowledge graph memory to maintain accurate data organization.
Instructions
Delete multiple entities and their associated relations from your Memento MCP knowledge graph memory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityNames | Yes | An array of entity names to delete |
Implementation Reference
- The main handler function that executes the delete_entities tool logic by delegating to KnowledgeGraphManager.deleteEntities and returning a success message.export async function handleDeleteEntities( args: Record<string, unknown>, // eslint-disable-next-line @typescript-eslint/no-explicit-any knowledgeGraphManager: any ): Promise<{ content: Array<{ type: string; text: string }> }> { await knowledgeGraphManager.deleteEntities(args.entityNames); return { content: [ { type: 'text', text: 'Entities deleted successfully', }, ], }; }
- Defines the tool schema including name, description, and inputSchema for validating arguments (array of entityNames).name: 'delete_entities', description: 'Delete multiple entities and their associated relations from your Memento MCP knowledge graph memory', inputSchema: { type: 'object', properties: { entityNames: { type: 'array', items: { type: 'string' }, description: 'An array of entity names to delete', }, }, required: ['entityNames'], }, },
- src/server/handlers/callToolHandler.ts:50-51 (registration)Registers the dispatch for 'delete_entities' tool in the switch statement of callToolHandler, routing to the specific handler.case 'delete_entities': return await toolHandlers.handleDeleteEntities(args, knowledgeGraphManager);
- src/server/handlers/toolHandlers/index.ts:8-8 (registration)Exports the handleDeleteEntities handler for use in callToolHandler.export { handleDeleteEntities } from './deleteEntities.js';
- src/KnowledgeGraphManager.ts:565-612 (helper)Core helper method in KnowledgeGraphManager that implements entity deletion, including removal from storage provider or file, related relations, and vector store.async deleteEntities(entityNames: string[]): Promise<void> { if (!entityNames || entityNames.length === 0) { return; } if (this.storageProvider) { // Use storage provider for deleting entities await this.storageProvider.deleteEntities(entityNames); } else { // Fallback to file-based implementation const graph = await this.loadGraph(); // Remove the entities const entitiesToKeep = graph.entities.filter((e) => !entityNames.includes(e.name)); // Remove relations involving the deleted entities const relationsToKeep = graph.relations.filter( (r) => !entityNames.includes(r.from) && !entityNames.includes(r.to) ); // Update the graph graph.entities = entitiesToKeep; graph.relations = relationsToKeep; await this.saveGraph(graph); } // Remove entities from vector store if available try { // Ensure vector store is available const vectorStore = await this.ensureVectorStore().catch(() => undefined); if (vectorStore) { for (const entityName of entityNames) { try { await vectorStore.removeVector(entityName); logger.debug(`Removed vector for entity ${entityName} from vector store`); } catch (error) { logger.error(`Failed to remove vector for entity ${entityName}`, error); // Don't throw here, continue with the next entity } } } } catch (error) { logger.error('Failed to remove vectors from vector store', error); // Continue even if vector store operations fail } }