update_relations
Modify multiple existing connections between entities in a knowledge graph to maintain accurate relationship data.
Instructions
Update multiple existing relations in the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes |
Implementation Reference
- index.ts:232-265 (handler)The core handler function in KnowledgeGraphManager that updates existing relations by merging provided data into matching relations, incrementing version, and persisting to the memory file.async updateRelations(relations: Relation[]): Promise<Relation[]> { const graph = await this.loadGraph(); const updatedRelations = relations.map(updateRelation => { const existingRelation = graph.relations.find(r => r.from === updateRelation.from && r.to === updateRelation.to && r.relationType === updateRelation.relationType ); if (!existingRelation) { throw new Error(`Relation not found`); } return { ...existingRelation, ...updateRelation, version: existingRelation.version + 1, createdAt: new Date().toISOString() }; }); // Update relations in the graph updatedRelations.forEach(updatedRelation => { const index = graph.relations.findIndex(r => r.from === updatedRelation.from && r.to === updatedRelation.to && r.relationType === updatedRelation.relationType ); if (index !== -1) { graph.relations[index] = updatedRelation; } }); await this.saveGraph(graph); return updatedRelations; }
- index.ts:483-500 (schema)JSON schema defining the input for the update_relations tool: an object containing an array of relations, each with 'from', 'to', and 'relationType' fields.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"], }, }, }, required: ["relations"], },
- index.ts:480-501 (registration)Registers the update_relations tool in the list_tools response, providing name, description, and input schema.{ name: "update_relations", description: "Update multiple existing relations in 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"], }, }, }, required: ["relations"], }, },
- index.ts:537-538 (registration)Dispatches the call_tool request for 'update_relations' to the KnowledgeGraphManager.updateRelations method in the switch statement.case "update_relations": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.updateRelations(args.relations as Relation[]), null, 2) }] };