create_relations
Establish directed connections between entities in Memento's memory system, avoiding duplicates to maintain clean relationship mapping.
Instructions
Create directed relations between entities. Skips existing relations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes | Array of relations to create. |
Implementation Reference
- src/knowledge-graph-manager.js:97-108 (handler)Core handler function that implements the logic for creating relations: resolves entity IDs, inserts relations via repository, and returns successfully created ones.async createRelations(relations) { const created = []; for (const relation of relations) { const fromId = await this.#repository.getOrCreateEntityId(relation.from, 'Unknown'); const toId = await this.#repository.getOrCreateEntityId(relation.to, 'Unknown'); const inserted = await this.#repository.createRelation(fromId, toId, relation.relationType); if (inserted) { created.push(relation); } } return created; }
- src/server.js:67-88 (registration)Registers the MCP tool 'create_relations' with name, description, input schema using Zod, and a thin handler that delegates to KnowledgeGraphManager.createRelations and formats response.// Tool: create_relations this.tool( 'create_relations', 'Create directed relations between entities. Skips existing relations.', { relations: z.array(z.object({ from: z.string().describe('Source entity name.'), to: z.string().describe('Target entity name.'), relationType: z.string().describe('Label or type of the relation.') })).describe('Array of relations to create.') }, async ({ relations }) => ({ content: [{ type: 'text', text: JSON.stringify( await this.#knowledgeGraphManager.createRelations(relations), null, 2 ) }] }) );
- src/server.js:71-77 (schema)Zod schema defining the input parameters for the 'create_relations' tool: array of relations with from, to, and relationType fields.{ relations: z.array(z.object({ from: z.string().describe('Source entity name.'), to: z.string().describe('Target entity name.'), relationType: z.string().describe('Label or type of the relation.') })).describe('Array of relations to create.') },