Skip to main content
Glama

add_canvas_edge

Connect two nodes in an Obsidian canvas by adding an edge between them, enabling visual relationships and structured workflows.

Instructions

Add an edge (connection) between two nodes in a canvas

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
canvasPathYesRelative path to the .canvas file
fromNodeYesSource node ID
toNodeYesTarget node ID
labelNoEdge label
fromSideNoSide of source node
toSideNoSide of target node

Implementation Reference

  • The handler function that adds an edge between two nodes in a canvas file, including node validation and updating the canvas data.
      async ({ canvasPath, fromNode, toNode, label, fromSide, toSide }) => {
        try {
          const data = await readCanvasFile(vaultPath, canvasPath);
    
          const fromExists = data.nodes.some((n) => n.id === fromNode);
          const toExists = data.nodes.some((n) => n.id === toNode);
    
          if (!fromExists) {
            return errorResult(`Error: source node '${fromNode}' not found in canvas.`);
          }
          if (!toExists) {
            return errorResult(`Error: target node '${toNode}' not found in canvas.`);
          }
    
          const id = randomUUID();
          const edge: CanvasData["edges"][number] = {
            id,
            fromNode,
            toNode,
          };
    
          if (label) edge.label = label;
          if (fromSide) edge.fromSide = fromSide;
          if (toSide) edge.toSide = toSide;
    
          data.edges.push(edge);
          await writeCanvasFile(vaultPath, canvasPath, data);
    
          return {
            content: [{ type: "text" as const, text: `Edge added successfully.\nID: ${id}\nFrom: ${fromNode} -> To: ${toNode}${label ? `\nLabel: ${label}` : ""}` }],
          };
        } catch (err) {
          console.error("Failed to add canvas edge:", err);
          return errorResult(`Error adding edge: ${err instanceof Error ? err.message : String(err)}`);
        }
      },
    );
  • Input schema definition for the add_canvas_edge tool using zod.
    {
      description: "Add an edge (connection) between two nodes in a canvas",
      inputSchema: {
        canvasPath: z.string().min(1).describe("Relative path to the .canvas file"),
        fromNode: z.string().describe("Source node ID"),
        toNode: z.string().describe("Target node ID"),
        label: z.string().optional().describe("Edge label"),
        fromSide: z.enum(["top", "right", "bottom", "left"]).optional().describe("Side of source node"),
        toSide: z.enum(["top", "right", "bottom", "left"]).optional().describe("Side of target node"),
      },
    },
  • Registration of the add_canvas_edge tool in the McpServer.
    server.registerTool(
      "add_canvas_edge",

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/rps321321/obsidian-mcp-pro'

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