Skip to main content
Glama
sureshsankaran

Obsidian Tools MCP Server

prepend_to_note

Add content to the start of existing notes in Obsidian vaults, maintaining frontmatter structure with customizable separators.

Instructions

Prepend content to the beginning of an existing note (after frontmatter if present)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the note relative to vault root
contentYesContent to prepend
separatorNoSeparator to add after prepended content. Default: '\n\n'

Implementation Reference

  • The core handler function implementing the 'prepend_to_note' tool logic. Reads the note, handles frontmatter specially by inserting after it, adds separator, and writes the updated content.
    async function handlePrependToNote(args: { path: string; content: string; separator?: string; }): Promise<string> { const fullPath = resolvePath(args.path); const separator = args.separator ?? "\n\n"; if (!(await fileExists(fullPath))) { throw new Error(`Note not found at ${args.path}`); } const existingContent = await fs.readFile(fullPath, "utf-8"); const { frontmatter, body, raw } = parseFrontmatter(existingContent); let newContent: string; if (frontmatter) { newContent = `---\n${raw}\n---\n${args.content}${separator}${body}`; } else { newContent = args.content + separator + existingContent; } await fs.writeFile(fullPath, newContent, "utf-8"); return `Successfully prepended content to ${args.path}`; }
  • Input schema defining the parameters for the 'prepend_to_note' tool: path (required), content (required), separator (optional with default).
    inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the note relative to vault root", }, content: { type: "string", description: "Content to prepend", }, separator: { type: "string", description: "Separator to add after prepended content. Default: '\\n\\n'", default: "\n\n", }, }, required: ["path", "content"], },
  • src/index.ts:106-130 (registration)
    Tool registration entry in the 'tools' array used for the listTools endpoint, including name, description, and schema.
    { name: "prepend_to_note", description: "Prepend content to the beginning of an existing note (after frontmatter if present)", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the note relative to vault root", }, content: { type: "string", description: "Content to prepend", }, separator: { type: "string", description: "Separator to add after prepended content. Default: '\\n\\n'", default: "\n\n", }, }, required: ["path", "content"], }, },
  • src/index.ts:883-887 (registration)
    Dispatch/registration in the switch statement of the CallToolRequestSchema handler that calls the specific tool handler.
    case "prepend_to_note": result = await handlePrependToNote( args as { path: string; content: string; separator?: string } ); break;
  • Helper function to parse frontmatter from note content, crucial for 'prepend_to_note' to insert content after frontmatter without corrupting it.
    function parseFrontmatter(content: string): { frontmatter: Record<string, unknown> | null; body: string; raw: string; } { const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/); if (match) { try { // Simple YAML parsing for common cases const yaml: Record<string, unknown> = {}; const lines = match[1].split("\n"); for (const line of lines) { const colonIndex = line.indexOf(":"); if (colonIndex > 0) { const key = line.slice(0, colonIndex).trim(); let value: unknown = line.slice(colonIndex + 1).trim(); // Handle arrays if (value === "") { value = []; } else if ( typeof value === "string" && value.startsWith("[") && value.endsWith("]") ) { value = value .slice(1, -1) .split(",") .map((v) => v.trim()); } yaml[key] = value; } } return { frontmatter: yaml, body: match[2], raw: match[1] }; } catch { return { frontmatter: null, body: content, raw: "" }; } } return { frontmatter: null, body: content, raw: "" }; }

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/sureshsankaran/obsidian-tools-mcp'

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