delete_relations
Remove specified relationships between entities in a knowledge graph to maintain accurate and relevant data connections. Supports optional memory zone targeting for precise deletions.
Instructions
Delete relationships from knowledge graph (memory)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memory_zone | No | Optional memory zone specifier. If provided, relations will be deleted from this zone. | |
| relations | Yes | List of relations to delete |
Implementation Reference
- src/kg-client.ts:630-658 (handler)Core handler implementation in KnowledgeGraphClient that deletes the Elasticsearch document for the specified relation using its constructed ID.async deleteRelation( from: string, to: string, relationType: string, fromZone?: string, toZone?: string ): Promise<boolean> { await this.initialize(); const actualFromZone = fromZone || this.defaultZone; const actualToZone = toZone || this.defaultZone; try { const relationId = `relation:${actualFromZone}:${from}:${relationType}:${actualToZone}:${to}`; await this.client.delete({ index: KG_RELATIONS_INDEX, id: relationId, refresh: true }); return true; } catch (error) { if (error.statusCode === 404) { return false; } throw error; } }
- src/index.ts:952-978 (handler)MCP server tool dispatch handler that loops over input relations and calls the core deleteRelation method.else if (toolName === "delete_relations") { const relations = params.relations; const zone = params.memory_zone; const results = []; // Delete each relation individually for (const relation of relations) { const success = await kgClient.deleteRelation( relation.from, relation.to, relation.type, zone, zone ); results.push({ from: relation.from, to: relation.to, type: relation.type, deleted: success }); } return formatResponse({ success: true, results }); }
- src/index.ts:297-323 (registration)Tool registration including name, description, and input schema in the ListToolsRequestSchema response.name: "delete_relations", description: "Delete relationships from knowledge graph (memory)", inputSchema: { type: "object", properties: { relations: { type: "array", description: "List of relations to delete", items: { type: "object", properties: { from: {type: "string", description: "Source entity name"}, to: {type: "string", description: "Target entity name"}, type: {type: "string", description: "Relationship type"} }, required: ["from", "to", "type"] } }, memory_zone: { type: "string", description: "Optional memory zone specifier. If provided, relations will be deleted from this zone." } }, required: ["relations"], additionalProperties: false, "$schema": "http://json-schema.org/draft-07/schema#" }
- legacy/index.ts:142-150 (handler)Legacy file-based handler in KnowledgeGraphManager that filters and removes matching relations from the in-memory graph and persists to file.async deleteRelations(relations: Relation[]): Promise<void> { const graph = await this.loadGraph(); graph.relations = graph.relations.filter(r => !relations.some(delRelation => r.from === delRelation.from && r.to === delRelation.to && r.relationType === delRelation.relationType )); await this.saveGraph(graph); }
- legacy/index.ts:439-461 (registration)Legacy tool registration and schema.{ name: "delete_relations", description: "Delete multiple relations from the knowledge graph", inputSchema: { type: "object", properties: { relations: { type: "array", items: { type: "object", properties: { from: { type: "string", description: "The name of the entity where the relation starts" }, to: { type: "string", description: "The name of the entity where the relation ends" }, relationType: { type: "string", description: "The type of the relation" }, }, required: ["from", "to", "relationType"], }, description: "An array of relations to delete" }, }, required: ["relations"], }, },