Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_diff_notes

Read-only

Compare two notes or a note with supplied text to produce a structured line diff.

Instructions

Compare two notes or compare a note with supplied text and return a structured line diff.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
leftPathYesVault-relative path. Absolute paths and traversal are rejected.
rightPathNo
rightTextNo
contextNo
maxLinesNo

Implementation Reference

  • src/tools.ts:886-908 (registration)
    Registration of the obsidian_diff_notes tool with McpServer. Defines the schema (vault, leftPath, rightPath, rightText, context, maxLines) and the handler that reads notes and calls diffLines.
      "obsidian_diff_notes",
      "Compare two notes or compare a note with supplied text and return a structured line diff.",
      {
        vault: vaultArg,
        leftPath: pathArg,
        rightPath: z.string().optional(),
        rightText: z.string().optional(),
        context: z.number().int().min(0).max(20).optional().default(3),
        maxLines: z.number().int().min(20).max(5000).optional().default(500),
      },
      async (args) => {
        const left = await vaults.readText(args.leftPath, args.vault);
        const right = args.rightText ?? (args.rightPath ? (await vaults.readText(args.rightPath, args.vault)).text : "");
        const diff = diffLines(left.text, right);
        return {
          left: left.path,
          right: args.rightPath ?? "(provided text)",
          changedLines: diff.filter((line) => line.type !== "same").length,
          diff: compactDiff(diff, args.context).slice(0, args.maxLines),
        };
      },
      { readOnlyHint: true },
    );
  • Handler logic for obsidian_diff_notes: reads left note from vault, gets right note text (either from rightPath or rightText), computes line diff using diffLines(), and returns structured diff with changedLines count and compacted diff.
    async (args) => {
      const left = await vaults.readText(args.leftPath, args.vault);
      const right = args.rightText ?? (args.rightPath ? (await vaults.readText(args.rightPath, args.vault)).text : "");
      const diff = diffLines(left.text, right);
      return {
        left: left.path,
        right: args.rightPath ?? "(provided text)",
        changedLines: diff.filter((line) => line.type !== "same").length,
        diff: compactDiff(diff, args.context).slice(0, args.maxLines),
      };
    },
  • Zod schema for obsidian_diff_notes tool parameters: vault (optional), leftPath (required), rightPath (optional), rightText (optional), context (default 3), maxLines (default 500).
    {
      vault: vaultArg,
      leftPath: pathArg,
      rightPath: z.string().optional(),
      rightText: z.string().optional(),
      context: z.number().int().min(0).max(20).optional().default(3),
      maxLines: z.number().int().min(20).max(5000).optional().default(500),
    },
  • The diffLines() function implementation. Uses a longest-common-subsequence (LCS) dynamic programming approach to produce a structured diff with 'same', 'removed', and 'added' line types.
    export function diffLines(a: string, b: string): Array<{ type: "same" | "removed" | "added"; line?: number; text: string }> {
      const left = a.replace(/\r\n/g, "\n").split("\n");
      const right = b.replace(/\r\n/g, "\n").split("\n");
      const dp: number[][] = Array.from({ length: left.length + 1 }, () => Array(right.length + 1).fill(0));
      for (let i = left.length - 1; i >= 0; i -= 1) {
        for (let j = right.length - 1; j >= 0; j -= 1) {
          dp[i][j] = left[i] === right[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
      const out: Array<{ type: "same" | "removed" | "added"; line?: number; text: string }> = [];
      let i = 0;
      let j = 0;
      while (i < left.length || j < right.length) {
        if (i < left.length && j < right.length && left[i] === right[j]) {
          out.push({ type: "same", line: i + 1, text: left[i] ?? "" });
          i += 1;
          j += 1;
        } else if (j >= right.length || (i < left.length && dp[i + 1][j] >= dp[i][j + 1])) {
          out.push({ type: "removed", line: i + 1, text: left[i] ?? "" });
          i += 1;
        } else {
          out.push({ type: "added", line: j + 1, text: right[j] ?? "" });
          j += 1;
        }
      }
      return out;
    }
  • The compactDiff() helper function. Filters a diff array to keep only changed lines plus surrounding context lines, used by the obsidian_diff_notes handler to limit output.
    function compactDiff(
      diff: Array<{ type: "same" | "removed" | "added"; line?: number; text: string }>,
      context: number,
    ): Array<{ type: "same" | "removed" | "added"; line?: number; text: string }> {
      if (context === 0) return diff.filter((line) => line.type !== "same");
      const keep = new Set<number>();
      diff.forEach((line, index) => {
        if (line.type === "same") return;
        for (let i = Math.max(0, index - context); i <= Math.min(diff.length - 1, index + context); i += 1) keep.add(i);
      });
      return diff.filter((_line, index) => keep.has(index));
    }
Behavior3/5

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

Annotations already indicate readOnlyHint=true and destructiveHint=false. The description adds 'return a structured line diff', which is consistent but does not elaborate on behavioral traits like handling of large files or limits. The transparency is adequate but minimal.

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 directly states what the tool does with no unnecessary words. It is appropriately front-loaded and concise.

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

Completeness3/5

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

No output schema is provided, and the description only mentions 'structured line diff' without specifying the structure. Parameters like context and maxLines affect output but are not explained. For a comparison tool, more completeness about output and parameters would be helpful.

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%), and the description does not explain the meaning of parameters like rightPath, rightText, context, or maxLines. The description implies two comparison modes but no details, failing to add value beyond the sparse schema.

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 the tool compares two notes or a note with supplied text and returns a structured line diff. The verb 'compare' and resource 'notes' are specific, and the tool is unique among siblings, which include no other diffing tools.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, such as querying notes individually. No when-not or explicit context for usage is given.

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