Skip to main content
Glama

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
NameRequiredDescriptionDefault
canvasPathYesRelative path to the .canvas file
typeYesNode type
contentYesText content, file path, URL, or group label depending on type
xNoX position
yNoY position
widthNoNode width
heightNoNode height
colorNoColor: '1'-'6' for Obsidian palette, or hex

Implementation Reference

  • 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)}`);
        }
      },
    );

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