Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_prune_empty_dirs

Find and remove empty directories in an Obsidian vault, working bottom-up while skipping .obsidian, .git, and .trash folders. Supports dry-run and configurable limits.

Instructions

Find and optionally remove empty directories bottom-up, skipping .obsidian, .git, and .trash.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
folderNo.
dryRunNo
limitNo

Implementation Reference

  • src/tools.ts:637-647 (registration)
    Registration of the obsidian_prune_empty_dirs tool using the MCP tool() helper. The schema specifies vault, folder, dryRun, and limit parameters. The handler delegates to pruneEmptyDirs() from ops.ts.
    tool(
      "obsidian_prune_empty_dirs",
      "Find and optionally remove empty directories bottom-up, skipping .obsidian, .git, and .trash.",
      {
        vault: vaultArg,
        folder: z.string().optional().default("."),
        dryRun: z.boolean().optional().default(true),
        limit: z.number().int().min(1).max(5000).optional().default(1000),
      },
      async (args) => pruneEmptyDirs(vaults, args.vault, args),
    );
  • The pruneEmptyDirs function implements the core logic: recursively walks directories bottom-up, skips .obsidian/.git/.trash, and removes empty directories. Supports dry-run mode and a configurable limit.
    export async function pruneEmptyDirs(
      vaults: VaultManager,
      vault: string | undefined,
      options: { folder?: string; dryRun?: boolean; limit?: number } = {},
    ): Promise<{ dryRun: boolean; removed: string[] }> {
      vaults.assertWritable();
      const base = vaults.resolvePath(options.folder ?? ".", vault);
      const removed: string[] = [];
      async function walk(dir: string): Promise<boolean> {
        const entries = await fs.readdir(dir, { withFileTypes: true });
        let empty = true;
        for (const entry of entries) {
          if ([".obsidian", ".git", ".trash"].includes(entry.name)) {
            empty = false;
            continue;
          }
          const full = path.join(dir, entry.name);
          if (entry.isDirectory()) {
            const childEmpty = await walk(full);
            if (!childEmpty) empty = false;
          } else {
            empty = false;
          }
        }
        if (empty && dir !== base.absolute && removed.length < (options.limit ?? 1000)) {
          const rel = path.relative(base.vault.root, dir).replace(/\\/g, "/");
          removed.push(rel);
          if (!options.dryRun) await fs.rmdir(dir);
          return true;
        }
        return false;
      }
      await walk(base.absolute);
      return { dryRun: options.dryRun ?? true, removed };
    }
  • Import of the pruneEmptyDirs function from ops.ts into the tools 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 discloses skipping certain directories and the option to remove (dryRun implied), but lacks details on side effects, reversibility, or security implications. Annotations are minimal and don't add much context beyond the description.

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 concise sentence that front-loads the action and key behaviors. Every word earns its place, with no redundancy.

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 complexity (4 parameters, no output schema, minimal annotations), the description is incomplete. It does not explain the return value, the effect of 'limit', or the behavior when dryRun is true. Significant gaps remain.

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 25% (one parameter described). The description adds minimal meaning: it hints at dryRun via 'optionally remove' but does not explain 'folder', 'limit', or their defaults. This is insufficient for effective use.

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 finds and optionally removes empty directories bottom-up, with specific exclusions. It is distinct from sibling tools like obsidian_delete_folder or obsidian_delete_note.

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 does not provide explicit guidance on when to use this tool versus alternatives. It only implicitly suggests use for cleaning empty directories, but no when-not conditions or sibling comparisons are 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