add_canvas_edge
Connect nodes in Obsidian canvas files by creating edges between them, allowing you to build relationships and visualize connections within your knowledge graph.
Instructions
Add an edge between nodes in canvas
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| canvasPath | Yes | Path to canvas file | |
| color | No | Edge color (1-6) | |
| fromNode | Yes | Source node ID | |
| label | No | Edge label | |
| toNode | Yes | Target node ID | |
| vault | Yes | Vault name |
Implementation Reference
- src/services/CanvasService.ts:265-295 (handler)Core implementation of adding an edge to a canvas file: reads the canvas JSON, creates a new CanvasEdge object with provided options, appends it to the edges array, and writes the updated canvas back to disk.async addEdge( vaultPath: string, canvasPath: string, options: CreateEdgeOptions ): Promise<VaultOperationResult<CanvasEdge>> { const canvasResult = await this.readCanvas(vaultPath, canvasPath); if (!canvasResult.success || !canvasResult.data) { return { success: false, error: canvasResult.error }; } const edge: CanvasEdge = { id: options.id || this.generateId(), fromNode: options.fromNode, fromSide: options.fromSide || 'right', fromEnd: options.fromEnd, toNode: options.toNode, toSide: options.toSide || 'left', toEnd: options.toEnd || 'arrow', color: options.color, label: options.label }; canvasResult.data.edges.push(edge); const writeResult = await this.writeCanvas(vaultPath, canvasPath, canvasResult.data); if (!writeResult.success) { return { success: false, error: writeResult.error }; } return { success: true, data: edge }; }
- src/index.ts:715-731 (handler)MCP tool handler dispatch for 'add_canvas_edge': validates local vault connector, extracts arguments, calls CanvasService.addEdge, and returns the result as JSON.case 'add_canvas_edge': { const connector = this.connectors.get(args?.vault as string); if (!connector || !connector.vaultPath) { throw new Error(`Vault "${args?.vault}" not found or not a local vault`); } const result = await this.canvasService.addEdge(connector.vaultPath, args?.canvasPath as string, { fromNode: args?.fromNode as string, toNode: args?.toNode as string, label: args?.label as string | undefined, color: args?.color as any, }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/index.ts:261-276 (schema)Tool registration and input schema definition for 'add_canvas_edge' in the ListTools response, specifying required parameters and their types.{ name: 'add_canvas_edge', description: 'Add an edge between nodes in canvas', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, canvasPath: { type: 'string', description: 'Path to canvas file' }, fromNode: { type: 'string', description: 'Source node ID' }, toNode: { type: 'string', description: 'Target node ID' }, label: { type: 'string', description: 'Edge label' }, color: { type: 'string', description: 'Edge color (1-6)' }, }, required: ['vault', 'canvasPath', 'fromNode', 'toNode'], }, },