Skip to main content
Glama
sureshsankaran

Obsidian Tools MCP Server

insert_at_heading

Insert content under a specific heading in an Obsidian note to organize information within sections.

Instructions

Insert content under a specific heading in a note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the note
headingYesThe heading text to insert content under
contentYesContent to insert
positionNoInsert at start or end of the heading section. Default: endend

Implementation Reference

  • The core handler function that executes the tool: reads the note, finds the specified heading using regex, determines the section end by next higher/same level heading, inserts content at start or end of the section, and writes back the file.
    async function handleInsertAtHeading(args: {
      path: string;
      heading: string;
      content: string;
      position?: "start" | "end";
    }): Promise<string> {
      const fullPath = resolvePath(args.path);
      const position = args.position ?? "end";
    
      if (!(await fileExists(fullPath))) {
        throw new Error(`Note not found at ${args.path}`);
      }
    
      const fileContent = await fs.readFile(fullPath, "utf-8");
      const lines = fileContent.split("\n");
    
      // Find the heading
      const headingPattern = new RegExp(`^#+\\s+${args.heading}\\s*$`);
      let headingIndex = -1;
    
      for (let i = 0; i < lines.length; i++) {
        if (headingPattern.test(lines[i])) {
          headingIndex = i;
          break;
        }
      }
    
      if (headingIndex === -1) {
        throw new Error(`Heading "${args.heading}" not found in ${args.path}`);
      }
    
      // Find the end of this section (next heading of same or higher level)
      const headingLevel = (lines[headingIndex].match(/^#+/) || [""])[0].length;
      let sectionEnd = lines.length;
    
      for (let i = headingIndex + 1; i < lines.length; i++) {
        const lineHeadingMatch = lines[i].match(/^#+/);
        if (lineHeadingMatch && lineHeadingMatch[0].length <= headingLevel) {
          sectionEnd = i;
          break;
        }
      }
    
      // Insert content
      if (position === "start") {
        lines.splice(headingIndex + 1, 0, "", args.content);
      } else {
        lines.splice(sectionEnd, 0, args.content, "");
      }
    
      await fs.writeFile(fullPath, lines.join("\n"), "utf-8");
      return `Successfully inserted content under heading "${args.heading}" in ${args.path}`;
    }
  • The input schema definition for the insert_at_heading tool, specifying parameters like path, heading, content, and optional position.
    {
      name: "insert_at_heading",
      description: "Insert content under a specific heading in a note",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "Path to the note",
          },
          heading: {
            type: "string",
            description: "The heading text to insert content under",
          },
          content: {
            type: "string",
            description: "Content to insert",
          },
          position: {
            type: "string",
            enum: ["start", "end"],
            description:
              "Insert at start or end of the heading section. Default: end",
            default: "end",
          },
        },
        required: ["path", "heading", "content"],
      },
    },
  • src/index.ts:920-928 (registration)
    The switch case in the CallToolRequest handler that routes calls to 'insert_at_heading' to the handleInsertAtHeading function.
    case "insert_at_heading":
      result = await handleInsertAtHeading(
        args as {
          path: string;
          heading: string;
          content: string;
          position?: "start" | "end";
        }
      );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool inserts content, implying a mutation operation, but doesn't cover critical aspects like whether it modifies existing content, requires specific permissions, handles errors (e.g., if the heading doesn't exist), or what the response looks like. This leaves significant gaps for an agent to understand the tool's behavior.

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, clear sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded with the main action and target, making it easy to parse quickly. Every part of the sentence earns its place by specifying key elements like 'content' and 'under a specific heading'.

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?

Given the tool's complexity (a mutation operation with 4 parameters) and the lack of annotations and output schema, the description is incomplete. It doesn't address behavioral traits, error handling, or return values, which are crucial for an agent to use the tool correctly in context with its siblings. The description alone is insufficient for safe and effective tool invocation.

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?

The description adds no parameter-specific information beyond what the input schema provides. Since schema description coverage is 100%, the baseline score is 3. The description doesn't elaborate on parameter meanings, constraints, or usage examples, so it doesn't compensate for or enhance the schema's documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Insert content') and target ('under a specific heading in a note'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'append_to_note' or 'prepend_to_note', which might have overlapping functionality for content insertion in notes.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., the note must exist), exclusions, or comparisons to siblings like 'append_to_note' (which might append to the entire note rather than under a heading) or 'update_note' (which might handle broader edits).

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