Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_shortest_path

Read-only

Find the shortest path between two notes in an Obsidian vault, using forward, backward, or bidirectional link traversal with configurable depth limit.

Instructions

Find a shortest graph path between two notes.

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
maxDepthNo
directionNoboth

Implementation Reference

  • The `shortestPath` function implements BFS over the vault link graph to find the shortest path between two notes. It is the core handler logic for the obsidian_shortest_path tool.
    export function shortestPath(
      graph: VaultGraph,
      fromPath: string,
      toPath: string,
      options: { maxDepth: number; direction: "forward" | "backward" | "both" },
    ): { path: string[]; edges: GraphEdge[] } | null {
      const from = resolveGraphPath(graph, fromPath);
      const to = resolveGraphPath(graph, toPath);
      if (!from || !to) return null;
      const queue: Array<{ path: string; route: string[]; edges: GraphEdge[] }> = [{ path: from.path, route: [from.path], edges: [] }];
      const seen = new Set<string>([from.path]);
      while (queue.length > 0) {
        const current = queue.shift();
        if (!current) continue;
        if (current.path === to.path) return { path: current.route, edges: current.edges };
        if (current.route.length - 1 >= options.maxDepth) continue;
        const edges = graph.edges.filter((edge) => {
          if (edge.unresolved) return false;
          if (options.direction === "forward") return edge.source === current.path;
          if (options.direction === "backward") return edge.target === current.path;
          return edge.source === current.path || edge.target === current.path;
        });
        for (const edge of edges) {
          const next = edge.source === current.path ? edge.target : edge.source;
          if (seen.has(next)) continue;
          seen.add(next);
          queue.push({ path: next, route: [...current.route, next], edges: [...current.edges, edge] });
        }
      }
      return null;
    }
  • The schema definition for obsidian_shortest_path tool: accepts from, to, maxDepth, direction args. The schema is defined via Zod in the tool registration.
    tool(
      "obsidian_shortest_path",
      "Find a shortest graph path between two notes.",
      {
        vault: vaultArg,
        from: pathArg,
        to: pathArg,
        maxDepth: z.number().int().min(1).max(10).optional().default(5),
        direction: z.enum(["forward", "backward", "both"]).optional().default("both"),
      },
      async (args) => ({ result: shortestPath(buildGraph(await loadNotes(vaults, args.vault)), args.from, args.to, args) }),
      { readOnlyHint: true },
    );
  • src/tools.ts:766-777 (registration)
    The registration of the obsidian_shortest_path tool in registerObsidianTools, binding the schema to the handler that calls shortestPath().
      "obsidian_shortest_path",
      "Find a shortest graph path between two notes.",
      {
        vault: vaultArg,
        from: pathArg,
        to: pathArg,
        maxDepth: z.number().int().min(1).max(10).optional().default(5),
        direction: z.enum(["forward", "backward", "both"]).optional().default("both"),
      },
      async (args) => ({ result: shortestPath(buildGraph(await loadNotes(vaults, args.vault)), args.from, args.to, args) }),
      { readOnlyHint: true },
    );
  • `resolveGraphPath` is a helper used by shortestPath to resolve a note path/name to a GraphNode, trying multiple candidate paths and stems.
    export function resolveGraphPath(graph: VaultGraph, input: string): GraphNode | null {
      const clean = normalizeNoteTarget(input);
      const candidates = [
        clean,
        clean.endsWith(".md") ? clean : `${clean}.md`,
        path.posix.basename(clean),
        `${path.posix.basename(clean)}.md`,
      ];
      for (const candidate of candidates) {
        const direct = graph.byPath.get(candidate);
        if (direct) return direct;
      }
      const stem = path.posix.basename(clean).replace(/\.md$/i, "").toLowerCase();
      const found = [...graph.byPath.values()].find((node) => noteStem(node.path).toLowerCase() === stem);
      return found ?? null;
    }
  • `createResolver` is a helper used by buildGraph to resolve link targets to file paths, which feeds into the graph edges used by shortestPath.
    export function createResolver(notes: NoteRecord[]): (target: string) => string | null {
      const byPath = new Map<string, string>();
      const byStem = new Map<string, string[]>();
      for (const note of notes) {
        byPath.set(note.path.toLowerCase(), note.path);
        byPath.set(note.path.replace(/\.md$/i, "").toLowerCase(), note.path);
        byPath.set(path.posix.basename(note.path).toLowerCase(), note.path);
        const stem = noteStem(note.path).toLowerCase();
        const list = byStem.get(stem) ?? [];
        list.push(note.path);
        byStem.set(stem, list);
      }
      return (target: string) => {
        const clean = normalizeNoteTarget(target).toLowerCase();
        const direct = byPath.get(clean) ?? byPath.get(`${clean}.md`);
        if (direct) return direct;
        const stem = path.posix.basename(clean).replace(/\.md$/i, "");
        const matches = byStem.get(stem);
        return matches?.length === 1 ? matches[0] : null;
      };
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, so the description's mention of 'find' aligns. However, it does not add behavioral details like algorithm used or assumptions about link direction, which are partially covered by the 'direction' parameter in schema.

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 with no wasted words. However, it could benefit from a brief expansion to cover parameter hints and usage context without becoming verbose.

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 has 5 parameters and siblings with overlapping functionality (e.g., obsidian_traverse_graph), the description lacks completeness. It does not explain when to use this tool, how parameters affect behavior, or what the output looks like.

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 coverage is only 40%, with descriptions for 'vault', 'from', 'to'. The description only implies 'from' and 'to' but does not explain 'maxDepth', 'direction', or 'vault'. Critical parameter context is missing.

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 'find' and resource 'shortest graph path', specifying it operates between two notes. It is distinct from siblings like obsidian_traverse_graph, which is more general.

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?

No guidance is provided on when to use this tool vs alternatives such as obsidian_traverse_graph or obsidian_graph_stats. The agent is left without context for selection.

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