Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_update_links

Rewrite wiki-links and Markdown links from one path to another within an Obsidian vault. Supports dry-run mode.

Instructions

Rewrite incoming wiki-links and Markdown links from one target path to another. Dry-run by default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
fromYesVault-relative path. Absolute paths and traversal are rejected.
toYes
dryRunNo

Implementation Reference

  • src/tools.ts:585-595 (registration)
    Registration of the obsidian_update_links tool in the MCP server with its Zod schema and handler that delegates to updateLinksAcrossVault.
    tool(
      "obsidian_update_links",
      "Rewrite incoming wiki-links and Markdown links from one target path to another. Dry-run by default.",
      {
        vault: vaultArg,
        from: pathArg,
        to: pathArg,
        dryRun: z.boolean().optional().default(true),
      },
      async (args) => ({ rewrites: await updateLinksAcrossVault(vaults, args.vault, vaults.notePath(args.from), vaults.notePath(args.to), { dryRun: args.dryRun }) }),
    );
  • Core handler that iterates all Markdown files in the vault, rewrites wiki-links ([[...]]) and Markdown links ([...](...)) from the old path to the new path, with dry-run support.
    export async function updateLinksAcrossVault(
      vaults: VaultManager,
      vault: string | undefined,
      fromPath: string,
      toPath: string,
      options: { dryRun?: boolean } = {},
    ): Promise<Array<{ path: string; changed: number; preview?: string }>> {
      const files = await vaults.markdownFiles(vault);
      const fromNoExt = fromPath.replace(/\.md$/i, "");
      const fromBase = path.posix.basename(fromNoExt);
      const toNoExt = toPath.replace(/\.md$/i, "");
      const rewrites: Array<{ path: string; changed: number; preview?: string }> = [];
      for (const file of files) {
        const read = await vaults.readText(file, vault);
        let changed = 0;
        let next = read.text.replace(/(!?)\[\[([^\]\n]+)\]\]/g, (full, embed: string, inner: string) => {
          const [targetAndSection, display] = inner.split("|", 2);
          const sectionMatch = /([#^].*)$/.exec(targetAndSection);
          const section = sectionMatch?.[1] ?? "";
          const target = targetAndSection.replace(/[#^].*$/, "").trim().replace(/\.md$/i, "");
          if (target !== fromNoExt && target !== fromBase && target !== fromPath) return full;
          changed += 1;
          return `${embed}[[${toNoExt}${section}${display ? `|${display}` : ""}]]`;
        });
        next = next.replace(/\[([^\]\n]+)\]\(([^)\n]+)\)/g, (full, label: string, target: string) => {
          const clean = decodeURIComponent(target).replace(/^\.\//, "");
          if (clean !== fromPath && clean !== fromNoExt && clean !== `${fromNoExt}.md`) return full;
          changed += 1;
          return `[${label}](${encodeURI(toPath)})`;
        });
        if (changed > 0) {
          rewrites.push({ path: read.path, changed, preview: options.dryRun ? previewDiff(read.text, next) : undefined });
          if (!options.dryRun) await vaults.writeText(read.path, next, vault, { overwrite: true });
        }
      }
      return rewrites;
    }
  • Helper used by updateLinksAcrossVault to generate a preview diff of changed lines for dry-run mode.
    function previewDiff(before: string, after: string): string {
      const beforeLines = before.split("\n");
      const afterLines = after.split("\n");
      const out: string[] = [];
      const max = Math.max(beforeLines.length, afterLines.length);
      for (let i = 0; i < max && out.length < 20; i += 1) {
        if (beforeLines[i] !== afterLines[i]) {
          if (beforeLines[i] !== undefined) out.push(`-${beforeLines[i]}`);
          if (afterLines[i] !== undefined) out.push(`+${afterLines[i]}`);
        }
      }
      return out.join("\n");
    }
  • Zod input schema for obsidian_update_links: vault (optional), from (path), to (path), dryRun (boolean, default true).
    {
      vault: vaultArg,
      from: pathArg,
      to: pathArg,
      dryRun: z.boolean().optional().default(true),
    },
    async (args) => ({ rewrites: await updateLinksAcrossVault(vaults, args.vault, vaults.notePath(args.from), vaults.notePath(args.to), { dryRun: args.dryRun }) }),
  • src/tools.ts:28-28 (registration)
    Import of updateLinksAcrossVault from ops.ts into tools.ts registration file.
    import { batchRename, deleteFolder, pruneEmptyDirs, regexReplaceAcrossVault, updateLinksAcrossVault } from "./ops.js";
Behavior3/5

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

The description adds the key behavioral detail that the tool performs a dry-run by default, which is not captured by annotations. However, it does not disclose that actual rewrites modify note files, the potential impact on broken links, or the operation's reversibility. Annotations (all false) provide minimal safety hints, so the description partially compensates but leaves gaps.

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 extremely concise—two brief clauses—and front-loads the primary action. Every word serves a purpose, and there is no redundancy. It could include more detail without becoming verbose, but given its length, it is 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?

The description omits important contextual details: it does not specify the scope of link rewriting (entire vault vs. specific notes), mention error handling or constraints, or describe the return value (e.g., count of updated links). Given the absence of an output schema, this lack of completeness hampers an agent's ability to infer proper usage and expected outcomes.

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?

The description adds value by clarifying the dryRun parameter's default behavior ('Dry-run by default'), which the schema leaves undocumented. However, it redundantly restates the from/to parameters without additional nuance, and vault is omitted. With 50% schema coverage, the description partially compensates but does not fully explain all parameters.

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 verb 'rewrite' and the resource 'incoming wiki-links and Markdown links', specifying the action of changing link targets from one path to another. This distinguishes it from sibling tools like obsidian_links (listing links) or obsidian_find_broken_links (finding broken links), making its purpose unmistakable.

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, nor does it mention prerequisites, scope, or typical use cases. The only contextual hint is the default dry-run behavior, which implies a safety check but does not offer explicit when-to-use or when-not-to-use advice.

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