Skip to main content
Glama

prepend_to_note

Add content to the beginning of an Obsidian note while preserving frontmatter. Use this tool to insert new information at the top of your notes.

Instructions

Prepend content to a note, after frontmatter if present

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesRelative path to the note
contentYesContent to prepend

Implementation Reference

  • The implementation of the prepend_to_note logic which reads the file, detects frontmatter, and prepends the new content either after the frontmatter or at the start of the file.
    export async function prependToNote(
      vaultPath: string,
      relativePath: string,
      content: string,
    ): Promise<void> {
      const fullPath = resolveVaultPath(vaultPath, relativePath);
      const existing = await fs.readFile(fullPath, "utf-8");
    
      // Detect frontmatter block (starts with --- on first line)
      const frontmatterMatch = existing.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);
    
      let result: string;
      if (frontmatterMatch) {
        const frontmatter = frontmatterMatch[0];
        const rest = existing.slice(frontmatter.length);
        const separator = frontmatter.endsWith("\n") ? "" : "\n";
        result = frontmatter + separator + content + "\n" + rest;
      } else {
        result = content + "\n" + existing;
      }
    
      await fs.writeFile(fullPath, result, "utf-8");
    }
  • The MCP tool registration for 'prepend_to_note', which validates inputs and calls the prependToNote handler.
    // 3. prepend_to_note
    server.registerTool(
      "prepend_to_note",
      {
        description: "Prepend content to a note, after frontmatter if present",
        inputSchema: {
          path: z.string().min(1).describe("Relative path to the note"),
          content: z.string().describe("Content to prepend"),
        },
      },
      async ({ path: notePath, content }) => {
        try {
          const resolvedPath = ensureMdExtension(notePath);
          await prependToNote(vaultPath, resolvedPath, content);
          return textResult(`Prepended content to '${resolvedPath}'.`);
        } catch (err) {
          console.error("prepend_to_note error:", err);
          return errorResult(`Error prepending to note: ${err instanceof Error ? err.message : String(err)}`);
        }
      },
    );

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/rps321321/obsidian-mcp-pro'

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