Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_patch_active

Modify the active note by appending, prepending, or replacing content at a heading, block reference, or frontmatter key using the Local REST API.

Instructions

Patch the active note by heading, block reference, or frontmatter key through Local REST API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetTypeYes
targetYes
operationYes
contentYes

Implementation Reference

  • src/tools.ts:1244-1244 (registration)
    The registration of 'obsidian_patch_active' tool within the registerObsidianTools function.
    );
  • Input schema for obsidian_patch_active: targetType (heading/block/frontmatter), target, operation (append/prepend/replace), and content.
    {
      targetType: z.enum(["heading", "block", "frontmatter"]),
      target: z.string(),
      operation: z.enum(["append", "prepend", "replace"]),
      content: z.string(),
    },
  • Handler that fetches the active note via REST API, patches the specified section using patchSection, and writes it back via PUT.
    async (args) => {
      const current = await getRestText(config, "/active/");
      const next = patchSection(current, selectorFrom(args.targetType, args.target), args.operation, args.content);
      return obsidianRestRequest(config, { method: "PUT", path: "/active/", body: next, contentType: "text/markdown" });
    },
  • The selectorFrom helper function that converts targetType/target values to a SectionSelector object used by patchSection.
    function selectorFrom(type: "heading" | "block" | "frontmatter", value: string): SectionSelector {
      if (type === "heading") return { type, heading: value };
      if (type === "block") return { type, block: value.replace(/^\^/, "") };
      return { type, key: value };
  • The patchSection function imported from markdown.ts that does the actual section patching.
    export function patchSection(
      markdown: string,
      selector: SectionSelector,
      operation: "append" | "prepend" | "replace",
      content: string,
    ): string {
      if (selector.type === "frontmatter") {
        const parsed = parseFrontmatter(markdown);
        const data = { ...parsed.data };
        if (operation === "replace") data[selector.key] = content;
        if (operation === "append") data[selector.key] = `${data[selector.key] ?? ""}${content}`;
        if (operation === "prepend") data[selector.key] = `${content}${data[selector.key] ?? ""}`;
        return stringifyFrontmatter(data, parsed.body);
      }
      const range = findSectionRange(markdown, selector);
      if (!range) throw new Error(`Section not found: ${JSON.stringify(selector)}`);
      if (operation === "replace") {
        return `${markdown.slice(0, range.start)}${content}${markdown.slice(range.end)}`;
      }
      if (operation === "prepend") {
        return `${markdown.slice(0, range.start)}${content}\n${markdown.slice(range.start)}`;
      }
      return `${markdown.slice(0, range.end).replace(/\s*$/, "\n")}${content}\n${markdown.slice(range.end).replace(/^\n?/, "")}`;
    }
    
    export function replaceTaskLine(
      markdown: string,
      lineNumber: number,
      update: { checked?: boolean; status?: string; text?: string },
    ): string {
      const lines = markdown.replace(/\r\n/g, "\n").split("\n");
      const idx = lineNumber - 1;
      const line = lines[idx];
      if (!line) throw new Error(`Line ${lineNumber} does not exist`);
      const match = /^(\s*[-*]\s+\[)([^\]])(\]\s+)(.*)$/.exec(line);
      if (!match) throw new Error(`Line ${lineNumber} is not a Markdown task`);
      const status = update.status ?? (update.checked === undefined ? match[2] : update.checked ? "x" : " ");
      const text = update.text ?? match[4];
      lines[idx] = `${match[1]}${status}${match[3]}${text}`;
      return lines.join("\n");
    }
    
    export function normalizeNoteTarget(target: string): string {
      const decoded = decodeURIComponent(target.trim());
      return decoded
        .replace(/\\/g, "/")
        .replace(/^\/+/, "")
        .replace(/\.md$/i, "");
    }
    
    export function noteStem(notePath: string): string {
      return path.posix.basename(notePath).replace(/\.md$/i, "");
    }
    
    export function escapeRegExp(value: string): string {
      return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
    }
    
    function offsetForLine(lines: string[], lineIndex: number): number {
      let offset = 0;
      for (let i = 0; i < lineIndex; i += 1) offset += (lines[i]?.length ?? 0) + 1;
      return offset;
    }
Behavior3/5

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

Annotations indicate readOnlyHint=false and destructiveHint=false, which are consistent with patching. The description adds that patching is done by heading, block, or frontmatter, but does not disclose details like whether targets are created if missing, or behavior on failure. There is no contradiction with annotations.

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 that front-loads the core action ('Patch the active note') and enumerates key input dimensions. It is concise with no wasted words, though slightly more structure could improve clarity.

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?

The tool has 4 required parameters, no output schema, and annotations are all false. The description does not explain return values, error conditions, or prerequisites (e.g., active note must be open). It is incomplete for a mutation tool of this complexity.

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 description coverage is 0%, so the description must compensate. It explains targetType (heading/block/frontmatter) and operation (implied by 'Patch'), but does not define 'block reference' or clarify the meaning of each operation (append/prepend/replace). This leaves ambiguity for the agent.

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 it patches the active note, specifying three distinct target types (heading, block reference, frontmatter key). This distinguishes it from sibling tools like obsidian_patch_note which likely patches a specific note by path.

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 explicit guidance on when to use this tool vs alternatives like obsidian_append_to_note or obsidian_replace_in_note. Usage is implied only by the description's mention of 'active note', but no exclusions or comparisons are 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