add_canvas_node
Add a new node to an Obsidian canvas file, specifying type, content, position, and dimensions for text, file, link, or group elements.
Instructions
Add a new node to an Obsidian canvas
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| canvasPath | Yes | Relative path to the .canvas file | |
| type | Yes | Node type | |
| content | Yes | Text content, file path, URL, or group label depending on type | |
| x | No | X position | |
| y | No | Y position | |
| width | No | Node width | |
| height | No | Node height | |
| color | No | Color: '1'-'6' for Obsidian palette, or hex |
Implementation Reference
- src/tools/canvas.ts:105-159 (handler)The "add_canvas_node" tool is registered and implemented within `src/tools/canvas.ts`. It takes parameters for canvas path, node type, content, position, and dimensions, then updates the canvas file.
server.registerTool( "add_canvas_node", { description: "Add a new node to an Obsidian canvas", inputSchema: { canvasPath: z.string().min(1).describe("Relative path to the .canvas file"), type: z.enum(["text", "file", "link", "group"]).describe("Node type"), content: z.string().describe("Text content, file path, URL, or group label depending on type"), x: z.number().optional().default(0).describe("X position"), y: z.number().optional().default(0).describe("Y position"), width: z.number().optional().default(250).describe("Node width"), height: z.number().optional().default(60).describe("Node height"), color: z.string().optional().describe("Color: '1'-'6' for Obsidian palette, or hex"), }, }, async ({ canvasPath, type, content, x, y, width, height, color }) => { try { const data = await readCanvasFile(vaultPath, canvasPath); const id = randomUUID(); const node: CanvasNode = { id, type, x, y, width, height, }; if (type === "text") { node.text = content; } else if (type === "file") { node.file = content; } else if (type === "link") { node.url = content; } else if (type === "group") { node.label = content; } if (color) { node.color = color; } data.nodes.push(node); await writeCanvasFile(vaultPath, canvasPath, data); return { content: [{ type: "text" as const, text: `Node added successfully.\nID: ${id}\nType: ${type}\nPosition: (${x}, ${y})` }], }; } catch (err) { console.error("Failed to add canvas node:", err); return errorResult(`Error adding node: ${err instanceof Error ? err.message : String(err)}`); } }, );