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
| Name | Required | Description | Default |
|---|---|---|---|
| canvasPath | Yes | Relative path to the .canvas file | |
| fromNode | Yes | Source node ID | |
| toNode | Yes | Target node ID | |
| label | No | Edge label | |
| fromSide | No | Side of source node | |
| toSide | No | Side of target node |
Implementation Reference
- src/tools/canvas.ts:174-210 (handler)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)}`); } }, ); - src/tools/canvas.ts:163-173 (schema)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"), }, }, - src/tools/canvas.ts:161-162 (registration)Registration of the add_canvas_edge tool in the McpServer.
server.registerTool( "add_canvas_edge",