Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_canvas_create

Create an Obsidian canvas by defining nodes and edges with automatic graph layout, enabling visual mapping of connected ideas.

Instructions

Create an Obsidian JSON Canvas from semantic nodes/edges with automatic graph layout.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
pathYesVault-relative path. Absolute paths and traversal are rejected.
nodesYes
edgesNo
directionNoTB
overwriteNo

Implementation Reference

  • The tool registration and handler for 'obsidian_canvas_create'. It defines the schema (vault, path, nodes, edges, direction, overwrite) and invokes createCanvas() from canvas.ts to build the canvas, then writes it to the vault.
    tool(
      "obsidian_canvas_create",
      "Create an Obsidian JSON Canvas from semantic nodes/edges with automatic graph layout.",
      {
        vault: vaultArg,
        path: pathArg,
        nodes: z.array(z.object({
          id: z.string().optional(),
          label: z.string(),
          type: z.enum(["text", "file", "link", "group"]).optional(),
          text: z.string().optional(),
          file: z.string().optional(),
          url: z.string().optional(),
          color: z.string().optional(),
          width: z.number().optional(),
          height: z.number().optional(),
        })).min(1),
        edges: z.array(z.object({ id: z.string().optional(), from: z.string(), to: z.string(), label: z.string().optional(), color: z.string().optional() })).optional().default([]),
        direction: z.enum(["TB", "BT", "LR", "RL"]).optional().default("TB"),
        overwrite: z.boolean().optional().default(false),
      },
      async (args) => {
        const canvas = createCanvas(args.nodes, args.edges, { direction: args.direction });
        const canvasPath = args.path.endsWith(".canvas") ? args.path : `${args.path}.canvas`;
        return { ...(await vaults.writeText(canvasPath, `${JSON.stringify(canvas, null, 2)}\n`, args.vault, { overwrite: args.overwrite })), summary: { nodes: canvas.nodes.length, edges: canvas.edges.length } };
      },
    );
  • The createCanvas() function that converts CanvasNodeInput/CanvasEdgeInput arrays into a CanvasFile (nodes and edges) with auto-generated IDs and dagre-based layout via relayoutCanvas().
    export function createCanvas(
      nodes: CanvasNodeInput[],
      edges: CanvasEdgeInput[],
      options: { direction?: "TB" | "BT" | "LR" | "RL"; nodeWidth?: number; nodeHeight?: number } = {},
    ): CanvasFile {
      const idMap = new Map<string, string>();
      const canvasNodes: CanvasNode[] = nodes.map((node, index) => {
        const id = node.id ?? makeId(node.label, index);
        idMap.set(node.label, id);
        idMap.set(id, id);
        const type = node.type ?? (node.file ? "file" : node.url ? "link" : "text");
        return {
          id,
          type,
          x: 0,
          y: 0,
          width: node.width ?? options.nodeWidth ?? 260,
          height: node.height ?? estimateHeight(node.text ?? node.label, options.nodeHeight ?? 90),
          label: node.label,
          text: type === "text" ? node.text ?? node.label : node.text,
          file: node.file,
          url: node.url,
          color: node.color,
        };
      });
      const canvasEdges: CanvasEdge[] = edges.map((edge, index) => ({
        id: edge.id ?? `edge-${index + 1}`,
        fromNode: resolveId(idMap, edge.from),
        toNode: resolveId(idMap, edge.to),
        label: edge.label,
        color: edge.color,
      }));
      return relayoutCanvas({ nodes: canvasNodes, edges: canvasEdges }, options);
    }
  • Type definitions CanvasNodeInput and CanvasEdgeInput used for input to createCanvas and patchCanvas.
    export type CanvasNodeInput = {
      id?: string;
      label: string;
      type?: "text" | "file" | "link" | "group";
      text?: string;
      file?: string;
      url?: string;
      color?: string;
      width?: number;
      height?: number;
    };
  • src/tools.ts:1061-1086 (registration)
    The tool is registered in the registerObsidianTools() function under the name 'obsidian_canvas_create' using the local 'tool' helper.
      "obsidian_canvas_create",
      "Create an Obsidian JSON Canvas from semantic nodes/edges with automatic graph layout.",
      {
        vault: vaultArg,
        path: pathArg,
        nodes: z.array(z.object({
          id: z.string().optional(),
          label: z.string(),
          type: z.enum(["text", "file", "link", "group"]).optional(),
          text: z.string().optional(),
          file: z.string().optional(),
          url: z.string().optional(),
          color: z.string().optional(),
          width: z.number().optional(),
          height: z.number().optional(),
        })).min(1),
        edges: z.array(z.object({ id: z.string().optional(), from: z.string(), to: z.string(), label: z.string().optional(), color: z.string().optional() })).optional().default([]),
        direction: z.enum(["TB", "BT", "LR", "RL"]).optional().default("TB"),
        overwrite: z.boolean().optional().default(false),
      },
      async (args) => {
        const canvas = createCanvas(args.nodes, args.edges, { direction: args.direction });
        const canvasPath = args.path.endsWith(".canvas") ? args.path : `${args.path}.canvas`;
        return { ...(await vaults.writeText(canvasPath, `${JSON.stringify(canvas, null, 2)}\n`, args.vault, { overwrite: args.overwrite })), summary: { nodes: canvas.nodes.length, edges: canvas.edges.length } };
      },
    );
  • The relayoutCanvas() function applies dagre layout to position nodes and compute edge sides. Called by createCanvas.
    export function relayoutCanvas(
      canvas: CanvasFile,
      options: { direction?: "TB" | "BT" | "LR" | "RL" } = {},
    ): CanvasFile {
      const graph = new dagre.graphlib.Graph();
      graph.setGraph({ rankdir: options.direction ?? "TB", nodesep: 70, ranksep: 100, marginx: 20, marginy: 20 });
      graph.setDefaultEdgeLabel(() => ({}));
      for (const node of canvas.nodes) graph.setNode(node.id, { width: node.width, height: node.height });
      for (const edge of canvas.edges) graph.setEdge(edge.fromNode, edge.toNode);
      dagre.layout(graph);
      const nodes = canvas.nodes.map((node) => {
        const positioned = graph.node(node.id);
        return positioned
          ? { ...node, x: Math.round(positioned.x - node.width / 2), y: Math.round(positioned.y - node.height / 2) }
          : node;
      });
      const nodeById = new Map(nodes.map((node) => [node.id, node]));
      const edges = canvas.edges.map((edge) => {
        const from = nodeById.get(edge.fromNode);
        const to = nodeById.get(edge.toNode);
        return from && to ? { ...edge, ...edgeSides(from, to) } : edge;
      });
      return { nodes, edges };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations show readOnlyHint=false, destructiveHint=false. The description adds 'automatic graph layout' but does not explain overwrite behavior or side effects. It would benefit from mentioning that overwrite=true may destroy existing content. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, highly concise with no wasted words. It front-loads the action and purpose. Could be improved with slight structuring but overall efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, nested arrays, no output schema), the description is too brief. It does not explain node/edge ID uniqueness, the effect of direction, or the overwrite flag. The return value (created canvas file) is not described. Significant gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is low (33%). The description adds meaning that nodes/edges are semantic and layout is automatic, but it fails to explain key parameters like direction, overwrite, or the node/edge structure details. The majority of parameters are undocumented in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Create an Obsidian JSON Canvas from semantic nodes/edges with automatic graph layout.' It specifies the verb (create), resource (Obsidian JSON Canvas), and key differentiating features (nodes/edges, auto-layout), distinguishing it from siblings like obsidian_canvas_patch and obsidian_canvas_read.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description lacks explicit guidance on when to use this tool versus alternatives like obsidian_canvas_patch or writing canvas files manually. The usage is implied by the name and purpose but not clearly stated, missing 'when not to use' or 'alternative tools'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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