add_edges
Add multiple edges between nodes in a knowledge graph to define relationships, including edge types and optional weights, using the MemoryMesh MCP server.
Instructions
Add multiple new edges between nodes in the knowledge graph. Edges should be in active voice
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| edges | Yes | Array of edges to add |
Input Schema (JSON Schema)
{
"properties": {
"edges": {
"description": "Array of edges to add",
"items": {
"description": "Edge to add",
"properties": {
"edgeType": {
"description": "The type of the edge",
"type": "string"
},
"from": {
"description": "The name of the node where the edge starts",
"type": "string"
},
"to": {
"description": "The name of the node where the edge ends",
"type": "string"
},
"weight": {
"description": "Optional edge weight (0-1 range). Defaults to 1 if not specified",
"maximum": 1,
"minimum": 0,
"type": "number"
}
},
"required": [
"from",
"to",
"edgeType"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"edges"
],
"type": "object"
}
Implementation Reference
- Main MCP tool handler for add_edges - processes the tool request and calls the knowledge graph managercase "add_edges": const addedEdges = await this.knowledgeGraphManager.addEdges(args.edges); return formatToolResponse({ data: {edges: addedEdges}, actionTaken: "Added edges to knowledge graph" });
- Core business logic for adding edges - validates edge uniqueness, node existence, and manages graph storageasync addEdges(edges: Edge[]): Promise<Edge[]> { try { this.emit('beforeAddEdges', {edges}); const graph = await this.storage.loadGraph(); // Validate edge uniqueness and node existence using GraphValidator const newEdges = edges.filter(edge => { GraphValidator.validateEdgeUniqueness(graph, edge); // Ensure weights are set return EdgeWeightUtils.ensureWeight(edge); }); if (newEdges.length === 0) { return []; } for (const edge of newEdges) { GraphValidator.validateNodeExists(graph, edge.from); GraphValidator.validateNodeExists(graph, edge.to); } graph.edges.push(...newEdges); await this.storage.saveGraph(graph); this.emit('afterAddEdges', {edges: newEdges}); return newEdges; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; throw new Error(errorMessage); } }
- MCP tool schema definition for add_edges - defines input validation and parameter structurename: "add_edges", description: "Add multiple new edges between nodes in the knowledge graph. Edges should be in active voice", inputSchema: { type: "object", properties: { edges: { type: "array", description: "Array of edges to add", items: { type: "object", description: "Edge to add", properties: { from: {type: "string", description: "The name of the node where the edge starts"}, to: {type: "string", description: "The name of the node where the edge ends"}, edgeType: {type: "string", description: "The type of the edge"}, weight: { type: "number", description: "Optional edge weight (0-1 range). Defaults to 1 if not specified", minimum: 0, maximum: 1 } }, required: ["from", "to", "edgeType"], }, }, }, required: ["edges"], }, },
- src/integration/tools/handlers/ToolHandlerFactory.ts:42-45 (registration)Tool handler registration - maps add_edges tool to the GraphToolHandler// First check static tools if (toolName.match(/^(add|update|delete)_(nodes|edges)$/)) { return this.graphHandler; }
- src/core/graph/Edge.ts:6-12 (schema)Core Edge type definition used by the add_edges implementationexport interface Edge { type: 'edge'; from: string; to: string; edgeType: string; weight?: number; // Optional weight property (0-1 range) }