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: "" };
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the tool modifies existing notes (implied mutation) and handles frontmatter intelligently, which is useful behavioral context. However, it doesn't mention permissions, error conditions (e.g., if note doesn't exist), or what happens to existing content beyond the prepend action.

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?

The description is a single, efficient sentence that front-loads the core purpose ('prepend content to the beginning of an existing note') and adds only essential qualification ('after frontmatter if present'). Every word earns its place with no redundancy or fluff.

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

Completeness3/5

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

For a mutation tool with no annotations and no output schema, the description is minimally adequate. It covers the basic operation and frontmatter handling but lacks details on error handling, return values, or side effects. Given the complexity (modifying files) and lack of structured safety hints, more context would be helpful.

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?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description doesn't add any parameter-specific details beyond what's in the schema (e.g., it doesn't explain 'path' format or 'content' constraints), meeting the baseline for high schema coverage.

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 specific action ('prepend content to the beginning of an existing note') and distinguishes it from sibling tools like 'append_to_note' by specifying the location ('beginning' vs. end). It also adds nuance about handling frontmatter, which further differentiates it from other note modification tools.

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

Usage Guidelines4/5

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

The description implies when to use this tool by specifying it's for prepending to 'an existing note', suggesting it shouldn't be used for creating new notes (use 'create_note' instead). However, it doesn't explicitly state when not to use it or name alternatives like 'append_to_note' or 'update_note' for comparison.

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

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