Skip to main content
Glama

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

NameRequiredDescriptionDefault
edgesYesArray 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

  • The switch case handler that executes the "add_edges" MCP tool logic by calling the knowledge graph manager to add edges and formatting the tool response.
    case "add_edges": const addedEdges = await this.knowledgeGraphManager.addEdges(args.edges); return formatToolResponse({ data: {edges: addedEdges}, actionTaken: "Added edges to knowledge graph" });
  • The tool definition including name, description, and input schema for validating parameters to the "add_edges" tool.
    { name: "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"], }, },
  • Registers the static tools, including "add_edges", into the central tools registry map by name.
    allStaticTools.forEach(tool => { this.tools.set(tool.name, tool); });
  • Core implementation of adding edges to the graph storage, with validation, events, and persistence. Called indirectly by the tool handler.
    async 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); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CheMiguel23/MemoryMesh'

If you have feedback or need assistance with the MCP directory API, please join our Discord server