Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_traverse_graph

Read-only

Walk the Obsidian note graph from a starting note through forward, backward, or both directions up to N hops to discover linked notes.

Instructions

Walk the note graph from a starting note for N hops in forward, backward, or both directions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
startYesVault-relative path. Absolute paths and traversal are rejected.
depthNo
directionNoboth
limitNo

Implementation Reference

  • src/tools.ts:751-763 (registration)
    Registration of the obsidian_traverse_graph tool with schema (vault, start path, depth, direction, limit) and a handler that calls traverseGraph from graph.ts
    tool(
      "obsidian_traverse_graph",
      "Walk the note graph from a starting note for N hops in forward, backward, or both directions.",
      {
        vault: vaultArg,
        start: pathArg,
        depth: z.number().int().min(1).max(6).optional().default(2),
        direction: z.enum(["forward", "backward", "both"]).optional().default("both"),
        limit: z.number().int().min(1).max(500).optional().default(100),
      },
      async (args) => traverseGraph(buildGraph(await loadNotes(vaults, args.vault)), args.start, args),
      { readOnlyHint: true },
    );
  • Input schema for the obsidian_traverse_graph tool: vault, start path, depth (1-6), direction (forward/backward/both), limit (1-500)
    {
      vault: vaultArg,
      start: pathArg,
      depth: z.number().int().min(1).max(6).optional().default(2),
      direction: z.enum(["forward", "backward", "both"]).optional().default("both"),
      limit: z.number().int().min(1).max(500).optional().default(100),
    },
  • Core handler for obsidian_traverse_graph. Performs BFS traversal of the vault link graph from a starting note, respecting depth, direction (forward/backward/both), and limit. Returns visited nodes and traversed edges.
    export function traverseGraph(
      graph: VaultGraph,
      startPath: string,
      options: { depth: number; direction: "forward" | "backward" | "both"; limit: number },
    ): { nodes: GraphNode[]; edges: GraphEdge[] } {
      const start = resolveGraphPath(graph, startPath);
      if (!start) return { nodes: [], edges: [] };
      const seen = new Set<string>([start.path]);
      const edgeSeen = new Set<string>();
      const queue: Array<{ path: string; depth: number }> = [{ path: start.path, depth: 0 }];
      const resultEdges: GraphEdge[] = [];
      while (queue.length > 0 && seen.size < options.limit) {
        const current = queue.shift();
        if (!current || current.depth >= options.depth) 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 key = `${edge.source}->${edge.target}:${edge.line}`;
          if (!edgeSeen.has(key)) {
            edgeSeen.add(key);
            resultEdges.push(edge);
          }
          const next = edge.source === current.path ? edge.target : edge.source;
          if (!seen.has(next)) {
            seen.add(next);
            queue.push({ path: next, depth: current.depth + 1 });
          }
          if (seen.size >= options.limit) break;
        }
      }
      return {
        nodes: [...seen].map((nodePath) => graph.byPath.get(nodePath)).filter((node): node is GraphNode => Boolean(node)),
        edges: resultEdges,
      };
    }
  • Helper used by traverseGraph to resolve a user-provided path to a GraphNode, trying the path as-is, with .md extension, basename-only, and stem matching.
    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;
    }
Behavior2/5

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

Annotations already indicate readOnlyHint=true, so the description's non-destructive nature adds no new behavioral insight. It does not disclose what the output represents (paths, nodes, edges) or how traversal handles loops or missing notes.

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?

A single sentence that is front-loaded with the action and includes all critical inputs (start, depth, direction). No wasted words; highly efficient.

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?

Given the absence of output schema and moderate parameter count, the description lacks details on return format (e.g., list of note paths, nested structure). It also does not explain the vault parameter or limits. Adequate for basic usage but incomplete for complex scenarios.

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 covers three of five parameters indirectly: start as 'starting note', depth as 'N hops', direction as 'forward, backward, or both'. However, vault and limit are not mentioned, and schema coverage is only 40%, so the description partially compensates but misses key 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 specifies it walks the note graph from a starting note for N hops in forward, backward, or both directions. This differentiates it from siblings like obsidian_vault_graph which cover the whole vault, and other note-reading 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?

No guidance on when to use this tool versus alternatives (e.g., obsidian_vault_graph for full vault graph, obsidian_get_backlinks for direct links). No exclusions or context provided.

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