Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_update_frontmatter

Idempotent

Update frontmatter in Obsidian notes by merging, replacing, or deleting YAML keys. Specify the note path and values to modify.

Instructions

Set, merge, replace, or delete frontmatter keys in a note.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
pathYesVault-relative path. Absolute paths and traversal are rejected.
actionYes
valuesNoYAML frontmatter object.
keysNo

Implementation Reference

  • src/tools.ts:374-393 (registration)
    Registration of the 'obsidian_update_frontmatter' tool with schema (vault, path, action, values, keys) and handler that reads the note, performs the update/merge/delete, and writes back.
    tool(
      "obsidian_update_frontmatter",
      "Set, merge, replace, or delete frontmatter keys in a note.",
      {
        vault: vaultArg,
        path: pathArg,
        action: z.enum(["merge", "replace", "delete"]),
        values: frontmatterArg,
        keys: z.array(z.string()).optional(),
      },
      async (args) => {
        const read = await vaults.readText(args.path, args.vault);
        let next: string;
        if (args.action === "delete") next = deleteFrontmatterKeys(read.text, args.keys ?? []);
        else next = updateFrontmatter(read.text, args.values ?? {}, args.action);
        await vaults.writeText(read.path, next, args.vault, { overwrite: true });
        return { path: read.path, frontmatter: parseFrontmatter(next).data };
      },
      { destructiveHint: false, idempotentHint: true },
    );
  • The handler function for obsidian_update_frontmatter: reads the note, calls deleteFrontmatterKeys or updateFrontmatter based on action, then writes the result back to the vault.
      async (args) => {
        const read = await vaults.readText(args.path, args.vault);
        let next: string;
        if (args.action === "delete") next = deleteFrontmatterKeys(read.text, args.keys ?? []);
        else next = updateFrontmatter(read.text, args.values ?? {}, args.action);
        await vaults.writeText(read.path, next, args.vault, { overwrite: true });
        return { path: read.path, frontmatter: parseFrontmatter(next).data };
      },
      { destructiveHint: false, idempotentHint: true },
    );
  • The updateFrontmatter helper function that merges or replaces frontmatter data in a markdown string and returns the updated markdown.
    export function updateFrontmatter(
      markdown: string,
      updates: Record<string, unknown>,
      mode: "merge" | "replace" = "merge",
    ): string {
      const parsed = parseFrontmatter(markdown);
      const data = mode === "replace" ? { ...updates } : { ...parsed.data, ...updates };
      return stringifyFrontmatter(data, parsed.body);
    }
  • The stringifyFrontmatter helper that serializes frontmatter data back into YAML frontmatter format (--- delimited).
    export function stringifyFrontmatter(data: Record<string, unknown>, body: string): string {
      const cleaned = Object.fromEntries(
        Object.entries(data).filter(([, value]) => value !== undefined),
      );
      if (Object.keys(cleaned).length === 0) {
        return body.startsWith("\n") ? body.slice(1) : body;
      }
      const yaml = YAML.stringify(cleaned).trimEnd();
      return `---\n${yaml}\n---\n${body.replace(/^\n+/, "")}`;
    }
  • The parseFrontmatter helper that parses YAML frontmatter from markdown text, returning structured data.
    export function parseFrontmatter(markdown: string): FrontmatterParse {
      const normalized = markdown.replace(/\r\n/g, "\n");
      if (!normalized.startsWith(`${FRONTMATTER_OPEN}\n`)) {
        return { data: {}, body: markdown, raw: null, hasFrontmatter: false };
      }
      const end = normalized.indexOf("\n---", FRONTMATTER_OPEN.length + 1);
      if (end < 0) {
        return { data: {}, body: markdown, raw: null, hasFrontmatter: false };
      }
      const closeEnd = normalized.indexOf("\n", end + 1);
      const raw = normalized.slice(FRONTMATTER_OPEN.length + 1, end);
      const body = closeEnd >= 0 ? normalized.slice(closeEnd + 1) : "";
      let data: Record<string, unknown> = {};
      try {
        const parsed = YAML.parse(raw);
        if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
          data = parsed as Record<string, unknown>;
        }
      } catch {
        data = {};
      }
      return { data, body, raw, hasFrontmatter: true };
    }
Behavior3/5

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

Annotations already indicate readOnlyHint=false, destructiveHint=false, idempotentHint=true, openWorldHint=false. The description aligns with these, confirming mutation and idempotency. It adds no additional behavioral context beyond the annotations, which is adequate.

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, efficient sentence that conveys the core functionality without any redundant or extraneous information.

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's complexity (5 params, enum, nested objects, no output schema), the description is too minimal. It does not explain how actions interact (e.g., delete requires keys, merge vs replace semantics) or indicate the outcome/return value.

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?

Input schema provides descriptions for parameters like 'action', 'values', 'keys' with 60% coverage. The description does not add extra meaning beyond what the schema offers, so a baseline score of 3 is appropriate.

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 ('Set, merge, replace, or delete') and resource ('frontmatter keys in a note'). It distinguishes from sibling tools like obsidian_patch_note or obsidian_get_frontmatter by focusing specifically on frontmatter manipulation.

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_patch_note, obsidian_upsert_note). The description lists actions but does not explain the appropriate context for each (merge vs replace vs delete).

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