Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_canvas_patch

Add, update, or remove semantic nodes and edges in an Obsidian canvas, with optional automatic relayout.

Instructions

Patch a canvas by adding/updating/removing semantic nodes and edges, with optional relayout.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
pathYesVault-relative path. Absolute paths and traversal are rejected.
addNodesNo
addEdgesNo
updateNodesNo
removeNodesNo
removeEdgesNo
relayoutNo
directionNoTB

Implementation Reference

  • src/tools.ts:1114-1145 (registration)
    Registration of the 'obsidian_canvas_patch' tool with its Zod schema and handler that reads the canvas file, calls patchCanvas(), and writes the result back.
    tool(
      "obsidian_canvas_patch",
      "Patch a canvas by adding/updating/removing semantic nodes and edges, with optional relayout.",
      {
        vault: vaultArg,
        path: pathArg,
        addNodes: 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(),
        })).optional(),
        addEdges: z.array(z.object({ id: z.string().optional(), from: z.string(), to: z.string(), label: z.string().optional(), color: z.string().optional() })).optional(),
        updateNodes: z.array(z.object({ match: z.string(), label: z.string().optional(), text: z.string().optional(), file: z.string().optional(), url: z.string().optional(), color: z.string().optional() })).optional(),
        removeNodes: z.array(z.string()).optional(),
        removeEdges: z.array(z.string()).optional(),
        relayout: z.boolean().optional().default(true),
        direction: z.enum(["TB", "BT", "LR", "RL"]).optional().default("TB"),
      },
      async (args) => {
        const canvasPath = args.path.endsWith(".canvas") ? args.path : `${args.path}.canvas`;
        const read = await vaults.readText(canvasPath, args.vault);
        const patched = patchCanvas(JSON.parse(read.text) as CanvasFile, args);
        await vaults.writeText(read.path, `${JSON.stringify(patched.canvas, null, 2)}\n`, args.vault, { overwrite: true });
        return { path: read.path, changes: patched.changes, summary: { nodes: patched.canvas.nodes.length, edges: patched.canvas.edges.length } };
      },
    );
  • The patchCanvas() function that adds/updates/removes nodes and edges, then optionally relayouts the canvas. Called by the tool handler in tools.ts.
    export function patchCanvas(
      canvas: CanvasFile,
      patch: {
        addNodes?: CanvasNodeInput[];
        addEdges?: CanvasEdgeInput[];
        updateNodes?: Array<{ match: string; label?: string; text?: string; file?: string; url?: string; color?: string }>;
        removeNodes?: string[];
        removeEdges?: string[];
        relayout?: boolean;
        direction?: "TB" | "BT" | "LR" | "RL";
      },
    ): { canvas: CanvasFile; changes: string[] } {
      const changes: string[] = [];
      const next: CanvasFile = {
        nodes: canvas.nodes.map((node) => ({ ...node })),
        edges: canvas.edges.map((edge) => ({ ...edge })),
      };
      const labels = labelMap(next.nodes);
      const removeNodeIds = new Set((patch.removeNodes ?? []).map((match) => findNode(next.nodes, match)?.id).filter((id): id is string => Boolean(id)));
      if (removeNodeIds.size > 0) {
        next.nodes = next.nodes.filter((node) => !removeNodeIds.has(node.id));
        next.edges = next.edges.filter((edge) => !removeNodeIds.has(edge.fromNode) && !removeNodeIds.has(edge.toNode));
        changes.push(`removed ${removeNodeIds.size} nodes`);
      }
      for (const update of patch.updateNodes ?? []) {
        const node = findNode(next.nodes, update.match);
        if (!node) continue;
        if (update.label !== undefined) node.label = update.label;
        if (update.text !== undefined) node.text = update.text;
        if (update.file !== undefined) node.file = update.file;
        if (update.url !== undefined) node.url = update.url;
        if (update.color !== undefined) node.color = update.color;
        changes.push(`updated ${node.id}`);
      }
      const idMap = new Map<string, string>(next.nodes.flatMap((node) => [[node.id, node.id], [nodeLabel(node), node.id]]));
      for (const node of patch.addNodes ?? []) {
        const id = node.id ?? makeId(node.label, next.nodes.length);
        idMap.set(node.label, id);
        next.nodes.push({
          id,
          type: node.type ?? (node.file ? "file" : node.url ? "link" : "text"),
          x: 0,
          y: 0,
          width: node.width ?? 260,
          height: node.height ?? estimateHeight(node.text ?? node.label, 90),
          label: node.label,
          text: node.text ?? node.label,
          file: node.file,
          url: node.url,
          color: node.color,
        });
        changes.push(`added ${id}`);
      }
      const removeEdgeIds = new Set(patch.removeEdges ?? []);
      next.edges = next.edges.filter((edge) => !removeEdgeIds.has(edge.id));
      if (removeEdgeIds.size > 0) changes.push(`removed ${removeEdgeIds.size} edges`);
      for (const edge of patch.addEdges ?? []) {
        next.edges.push({
          id: edge.id ?? `edge-${next.edges.length + 1}`,
          fromNode: resolveId(idMap, edge.from),
          toNode: resolveId(idMap, edge.to),
          label: edge.label,
          color: edge.color,
        });
        changes.push(`added edge ${edge.from} -> ${edge.to}`);
      }
      return {
        canvas: patch.relayout === false ? next : relayoutCanvas(next, { direction: patch.direction ?? "TB" }),
        changes,
      };
    }
  • Zod schema for obsidian_canvas_patch: accepts addNodes, addEdges, updateNodes, removeNodes, removeEdges, relayout, and direction parameters.
      vault: vaultArg,
      path: pathArg,
      addNodes: 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(),
      })).optional(),
      addEdges: z.array(z.object({ id: z.string().optional(), from: z.string(), to: z.string(), label: z.string().optional(), color: z.string().optional() })).optional(),
      updateNodes: z.array(z.object({ match: z.string(), label: z.string().optional(), text: z.string().optional(), file: z.string().optional(), url: z.string().optional(), color: z.string().optional() })).optional(),
      removeNodes: z.array(z.string()).optional(),
      removeEdges: z.array(z.string()).optional(),
      relayout: z.boolean().optional().default(true),
      direction: z.enum(["TB", "BT", "LR", "RL"]).optional().default("TB"),
    },
  • relayoutCanvas() helper function used by patchCanvas to apply dagre auto-layout after patching nodes/edges.
    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 };
    }
  • findNode() helper used by patchCanvas to locate nodes by id or label for update/removal operations.
    function findNode(nodes: CanvasNode[], match: string): CanvasNode | undefined {
      const lower = match.toLowerCase();
      return nodes.find((node) => node.id === match || nodeLabel(node).toLowerCase() === lower)
        ?? nodes.find((node) => nodeLabel(node).toLowerCase().includes(lower));
    }
Behavior3/5

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

Annotations are all false (no readOnly, destructive, idempotent, openWorld hints), so the description carries the transparency burden. It discloses the tool modifies the canvas (add/update/remove) and optionally relayouts, but does not explain how updates work (by matching id), that relayout defaults to true, or whether operations are additive or overwrite. It provides moderate but incomplete behavioral context beyond the high-level action.

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

Conciseness5/5

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

The description is a single sentence that immediately states the tool's purpose and key operations. It is concise with no wasted words, front-loading the most important information (verb, resource, modifiers). Every part of the sentence earns its place.

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?

The tool has 9 parameters, no output schema, and moderate complexity with arrays. The description is extremely brief (one sentence) and omits critical details such as return value (no output schema), default values (relayout defaults to true), required fields in nested objects (addNodes requires label), and matching logic for updates. For a tool of this complexity, the description is insufficient to fully understand usage without inspecting the schema.

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

Parameters3/5

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

Schema_description_coverage is 22% (only vault and path have descriptions). The description compensates slightly by grouping parameters into semantic actions (addNodes, addEdges, updateNodes, removeNodes, removeEdges, relayout, direction). However, it does not explain that addNodes requires 'label', updateNodes uses 'match', or that relayout defaults to true. Without the schema descriptions being comprehensive, the description should provide more detail to bridge the gap; it does so only partially.

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 uses a specific verb 'Patch' and clearly states the resource 'canvas'. It enumerates the operations: adding, updating, removing semantic nodes and edges, and mentions optional relayout. This distinguishes it from sibling tools like obsidian_canvas_create (create new), obsidian_canvas_read (read-only), and obsidian_canvas_relayout (only relayout), providing clarity on its combined modification+relayout purpose.

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 does not explicitly state when to use this tool over alternatives. It only implies usage for modifying existing canvases (via required path) but lacks directives like 'Use this for modifications; for new canvases use obsidian_canvas_create'. There is no guidance on when not to use it or mention of prerequisites, so the usage guidance is implicit at best.

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