Skip to main content
Glama
bezata

kObsidian MCP

Edit Note

notes.edit

Mutate the body of an existing Obsidian note using replace, append, prepend, insert after heading, or insert after block reference modes. Fails if note does not exist; create it first with notes.create.

Instructions

Mutate the body of an existing note. The mode field selects how content is applied: replace overwrites the whole note; append adds to the end; prepend adds after the frontmatter (or at the top if none); after-heading inserts after the first heading whose text matches anchor (no leading #); after-block inserts after the block reference ^anchor. Fails if the note does not exist — use notes.create first. replace mode is idempotent-destructive; the others are additive.

Operates on the session-active vault (see vault.current — selectable via vault.select) unless an explicit vaultPath argument is passed, which always wins.

Examples:

Example 1 — Append a new journal entry to the end of today's note:

{
  "mode": "append",
  "path": "Journal/2026-04-24.md",
  "content": "\n## Afternoon\n\nFinished the tool consolidation."
}

Example 2 — Insert content after a specific heading:

{
  "mode": "after-heading",
  "path": "Projects/Alpha.md",
  "anchor": "Open questions",
  "content": "- Do we need to bump the Zod major?\n"
}

Example 3 — Insert after a block reference:

{
  "mode": "after-block",
  "path": "Notes/idea.md",
  "anchor": "idea-1",
  "content": "Follow-up thought …"
}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
changedYesTrue if the tool altered vault state on this call; false if it was a no-op.
targetYesThe path or identifier the tool acted on.
summaryYesShort human-readable summary of what happened.

Implementation Reference

  • The handler function for notes.edit that dispatches to the appropriate domain function based on the mode: replace, append, prepend, after-heading, or after-block.
    async function handleEdit(context: DomainContext, args: NotesEditArgs) {
      if (args.mode === "replace") {
        return updateNote(context, {
          path: args.path,
          content: args.content,
          mergeStrategy: "replace",
          vaultPath: args.vaultPath,
        });
      }
      if (args.mode === "append") {
        return appendToNote(context, {
          filePath: args.path,
          content: args.content,
          vaultPath: args.vaultPath,
        });
      }
      if (args.mode === "prepend") {
        // No dedicated prepend domain fn — compose via read+replace.
        const existing = await readNote(context, { path: args.path, vaultPath: args.vaultPath });
        return updateNote(context, {
          path: args.path,
          content: `${args.content}${existing.content.startsWith("\n") ? "" : "\n"}${existing.content}`,
          mergeStrategy: "replace",
          vaultPath: args.vaultPath,
        });
      }
      if (args.mode === "after-heading") {
        return insertAfterHeading(context, {
          filePath: args.path,
          heading: args.anchor,
          content: args.content,
          vaultPath: args.vaultPath,
        });
      }
      return insertAfterBlock(context, {
        filePath: args.path,
        blockId: args.anchor,
        content: args.content,
        vaultPath: args.vaultPath,
      });
    }
  • Tool registration for notes.edit, defining name, title, description, input/output schemas, annotations, and handler.
    {
      name: "notes.edit",
      title: "Edit Note",
      description:
        "Mutate the body of an existing note. The `mode` field selects how `content` is applied: `replace` overwrites the whole note; `append` adds to the end; `prepend` adds after the frontmatter (or at the top if none); `after-heading` inserts after the first heading whose text matches `anchor` (no leading `#`); `after-block` inserts after the block reference `^anchor`. Fails if the note does not exist — use `notes.create` first. `replace` mode is idempotent-destructive; the others are additive.",
      inputSchema: notesEditArgsSchema,
      outputSchema: mutationResultSchema,
      annotations: ADDITIVE,
      handler: async (context, rawArgs) => {
        const args = notesEditArgsSchema.parse(rawArgs) as NotesEditArgs;
        return handleEdit(context, args);
      },
      inputExamples: [
        {
          description: "Append a new journal entry to the end of today's note",
          input: {
            mode: "append",
            path: "Journal/2026-04-24.md",
            content: "\n## Afternoon\n\nFinished the tool consolidation.",
          },
        },
        {
          description: "Insert content after a specific heading",
          input: {
            mode: "after-heading",
            path: "Projects/Alpha.md",
            anchor: "Open questions",
            content: "- Do we need to bump the Zod major?\n",
          },
        },
        {
          description: "Insert after a block reference",
          input: {
            mode: "after-block",
            path: "Notes/idea.md",
            anchor: "idea-1",
            content: "Follow-up thought …",
          },
        },
      ],
    },
  • Input schema for notes.edit — a discriminated union on 'mode' with five variants: replace, append, prepend, after-heading, after-block.
    export const notesEditArgsSchema = z
      .discriminatedUnion("mode", [
        editReplaceShape,
        editAppendShape,
        editPrependShape,
        editAfterHeadingShape,
        editAfterBlockShape,
      ])
      .describe(
        "Discriminated union on `mode`. `replace` overwrites the whole note body; `append` adds to the end; `prepend` adds to the start (after frontmatter); `after-heading` inserts after a heading (anchor = heading text, no `#`); `after-block` inserts after a block reference (anchor = block id, no `^`).",
      );
  • Individual Zod shapes for each notes.edit mode variant, defining the required and optional fields (path, content, anchor, vaultPath).
    const editReplaceShape = z.object({
      mode: z.literal("replace"),
      path: notePathSchema,
      content: z.string().describe("Replacement body for the entire note."),
      vaultPath: z.string().optional(),
    });
    
    const editAppendShape = z.object({
      mode: z.literal("append"),
      path: notePathSchema,
      content: z.string(),
      vaultPath: z.string().optional(),
    });
    
    const editPrependShape = z.object({
      mode: z.literal("prepend"),
      path: notePathSchema,
      content: z.string(),
      vaultPath: z.string().optional(),
    });
    
    const editAfterHeadingShape = z.object({
      mode: z.literal("after-heading"),
      path: notePathSchema,
      content: z.string(),
      anchor: z
        .string()
        .min(1)
        .describe(
          "Heading text (without the leading `#`s) to insert after. Matches the first heading in the note that has this exact text.",
        ),
      vaultPath: z.string().optional(),
    });
    
    const editAfterBlockShape = z.object({
      mode: z.literal("after-block"),
      path: notePathSchema,
      content: z.string(),
      anchor: z
        .string()
        .min(1)
        .describe("Block id (without the `^` prefix) to insert after. Obsidian block refs only."),
      vaultPath: z.string().optional(),
    });
  • Supporting domain functions used by notes.edit handleEdit: insertAfterHeading, insertAfterBlock, and appendToNote (along with updateNote in notes.ts for replace/prepend).
    export async function insertAfterHeading(
      context: DomainContext,
      args: { filePath: string; heading: string; content: string; vaultPath?: string },
    ) {
      const vaultRoot = requireVaultPath(context, args.vaultPath);
      const absolutePath = resolveVaultPath(vaultRoot, args.filePath);
      const original = await readUtf8(absolutePath);
      const lines = original.split(/\r?\n/);
      const index = lines.findIndex((line) =>
        new RegExp(`^#{1,6}\\s+${escapeRegExp(args.heading)}\\s*$`).test(line),
      );
      if (index < 0) {
        return { changed: false, target: args.filePath, error: `Heading '${args.heading}' not found` };
      }
      lines.splice(index + 1, 0, args.content);
      await writeUtf8(absolutePath, `${lines.join("\n")}${original.endsWith("\n") ? "\n" : ""}`);
      return {
        changed: true,
        target: args.filePath,
        summary: `Inserted content after heading ${args.heading}`,
      };
    }
    
    export async function insertAfterBlock(
      context: DomainContext,
      args: { filePath: string; blockId: string; content: string; vaultPath?: string },
    ) {
      const vaultRoot = requireVaultPath(context, args.vaultPath);
      const absolutePath = resolveVaultPath(vaultRoot, args.filePath);
      const original = await readUtf8(absolutePath);
      const blockId = args.blockId.startsWith("^") ? args.blockId : `^${args.blockId}`;
      const lines = original.split(/\r?\n/);
      const index = lines.findIndex((line) =>
        new RegExp(`\\s${escapeRegExp(blockId)}\\s*$`).test(line),
      );
      if (index < 0) {
        return { changed: false, target: args.filePath, error: `Block '${blockId}' not found` };
      }
      lines.splice(index + 1, 0, args.content);
      await writeUtf8(absolutePath, `${lines.join("\n")}${original.endsWith("\n") ? "\n" : ""}`);
      return {
        changed: true,
        target: args.filePath,
        summary: `Inserted content after block ${blockId}`,
      };
    }
    
    export async function updateFrontmatterField(
      context: DomainContext,
      args: { filePath: string; field: string; value: unknown; vaultPath?: string },
    ) {
      const vaultRoot = requireVaultPath(context, args.vaultPath);
      const absolutePath = resolveVaultPath(vaultRoot, args.filePath);
      const original = await readUtf8(absolutePath);
      const parsed = parseFrontmatter(original);
      parsed.data[args.field] = args.value;
      await writeUtf8(absolutePath, stringifyFrontmatter(parsed));
      return {
        changed: true,
        target: args.filePath,
        summary: `Updated frontmatter field ${args.field}`,
      };
    }
    
    export async function appendToNote(
      context: DomainContext,
      args: { filePath: string; content: string; vaultPath?: string },
    ) {
      const vaultRoot = requireVaultPath(context, args.vaultPath);
      const absolutePath = resolveVaultPath(vaultRoot, args.filePath);
      const original = await readUtf8(absolutePath);
      await writeUtf8(absolutePath, `${original}${args.content}`);
      return { changed: true, target: args.filePath, summary: `Appended content to ${args.filePath}` };
    }
    
    export function escapeRegExp(value: string): string {
      return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
    }
Behavior1/5

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

Description mentions destructive behavior ('replace mode is idempotent-destructive'), but annotations set destructiveHint=false, a direct contradiction. Description also implies non-idempotent behavior, but idempotentHint=false, which is fine. The overriding issue is the destructive contradiction.

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?

Description is front-loaded with the main action and mode descriptions. Examples are provided without redundancy. Every sentence is substantive and earned its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers mode behavior, prerequisites, vault context, and failure cases. With an output schema present, return values need not be described. Examples cover all modes, making it complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has zero parameters, so the description carries the full burden. It thoroughly explains the 'mode', 'path', 'content', 'anchor', and 'vaultPath' parameters with examples, adding rich semantics beyond the empty schema.

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 'Mutate the body of an existing note' with a specific verb and resource. It distinguishes from 'notes.create' by noting that the tool fails if the note doesn't exist, so the agent knows to create first.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says 'Fails if the note does not exist — use `notes.create` first' and explains when to use different modes. Context about vault selection and vaultPath is provided, giving clear guidance.

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/bezata/kObsidian'

If you have feedback or need assistance with the MCP directory API, please join our Discord server