update_relations
Modifies existing relationships within the knowledge graph by updating 'from', 'to', and 'relationType' attributes for multiple connections, ensuring accurate data representation in the Knowledge Graph Memory Server.
Instructions
Update multiple existing relations in the knowledge graph
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes |
Input Schema (JSON Schema)
{
"properties": {
"relations": {
"items": {
"properties": {
"from": {
"description": "The name of the entity where the relation starts",
"type": "string"
},
"relationType": {
"description": "The type of the relation",
"type": "string"
},
"to": {
"description": "The name of the entity where the relation ends",
"type": "string"
}
},
"required": [
"from",
"to",
"relationType"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"relations"
],
"type": "object"
}
Implementation Reference
- index.ts:232-265 (handler)Core handler function in KnowledgeGraphManager that updates existing relations by matching on from/to/relationType, merging updates, incrementing version, saving the graph, and returning updated relations.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:480-501 (registration)Tool registration in the listTools response, including 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:483-500 (schema)JSON Schema for the input parameters of the update_relations tool.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 (handler)Dispatcher case in the CallToolRequestHandler that calls the updateRelations method with parsed arguments and formats the response.case "update_relations": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.updateRelations(args.relations as Relation[]), null, 2) }] };
- index.ts:39-45 (schema)TypeScript interface defining the structure of a Relation object used by the tool.interface Relation { from: string; to: string; relationType: string; createdAt: string; version: number; }