Skip to main content
Glama

List Sections

list_sections
Read-onlyIdempotent

List all headings in a note as a tree of paths with depth to identify valid section arguments for get_note, update_section, or insert_at_section.

Instructions

List all headings in a note as a tree of paths (with depth). Useful for discovering valid section arguments before calling get_note, update_section, or insert_at_section.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesVault-relative path to the note.

Implementation Reference

  • The async handler function for the 'list_sections' tool. It reads the note content via readNote, parses headings using parseHeadings, and returns a formatted tree of heading paths with indentation reflecting depth.
    async ({ path: notePath }) => {
      try {
        const { readNote } = await import("../lib/vault.js");
        const content = await readNote(vaultPath, notePath);
        const headings = parseHeadings(content);
        if (headings.length === 0) return textResult(`No headings in ${notePath}`);
        const lines = [`${headings.length} heading(s) in ${notePath}:`, ""];
        for (const h of headings) {
          lines.push(`${"  ".repeat(h.level - 1)}${"#".repeat(h.level)} ${h.text}`);
        }
        return textResult(lines.join("\n"));
      } catch (err) {
        log.error("list_sections failed", { tool: "list_sections", err: err as Error });
        return errorResult(`Error listing sections: ${sanitizeError(err)}`);
      }
    },
  • The input schema definition for 'list_sections'. It defines a single required string parameter 'path' (vault-relative path to the note). Annotations declare it as read-only and idempotent.
    {
      title: "List Sections",
      description:
        "List all headings in a note as a tree of paths (with depth). Useful for discovering valid `section` arguments before calling get_note, update_section, or insert_at_section.",
      annotations: {
        readOnlyHint: true,
        idempotentHint: true,
        openWorldHint: false,
      },
      inputSchema: {
        path: z.string().min(1).describe("Vault-relative path to the note."),
      },
    },
  • Registration of the 'list_sections' tool via server.registerTool with the name 'list_sections', schema, and handler within registerSectionTools.
    server.registerTool(
      "list_sections",
      {
        title: "List Sections",
        description:
          "List all headings in a note as a tree of paths (with depth). Useful for discovering valid `section` arguments before calling get_note, update_section, or insert_at_section.",
        annotations: {
          readOnlyHint: true,
          idempotentHint: true,
          openWorldHint: false,
        },
        inputSchema: {
          path: z.string().min(1).describe("Vault-relative path to the note."),
        },
      },
      async ({ path: notePath }) => {
        try {
          const { readNote } = await import("../lib/vault.js");
          const content = await readNote(vaultPath, notePath);
          const headings = parseHeadings(content);
          if (headings.length === 0) return textResult(`No headings in ${notePath}`);
          const lines = [`${headings.length} heading(s) in ${notePath}:`, ""];
          for (const h of headings) {
            lines.push(`${"  ".repeat(h.level - 1)}${"#".repeat(h.level)} ${h.text}`);
          }
          return textResult(lines.join("\n"));
        } catch (err) {
          log.error("list_sections failed", { tool: "list_sections", err: err as Error });
          return errorResult(`Error listing sections: ${sanitizeError(err)}`);
        }
      },
    );
  • The parseHeadings helper function that parses all ATX headings from markdown content, skipping fenced code blocks and frontmatter. Returns an array of Heading objects with level, text, and byte offsets.
    export function parseHeadings(content: string): Heading[] {
      const out: Heading[] = [];
      const start = bodyOffset(content);
      const fence = newFenceState();
      let cursor = start;
      // Walk line-by-line preserving byte offsets.
      while (cursor < content.length) {
        const nl = content.indexOf("\n", cursor);
        const lineEnd = nl === -1 ? content.length : nl;
        const line = content.slice(cursor, lineEnd);
        const lineEndExclusive = nl === -1 ? content.length : nl + 1;
    
        const isFenceLine = updateFence(fence, line);
        if (!isFenceLine && !fence.insideFence) {
          const m = line.match(ATX_HEADING_RE);
          if (m) {
            out.push({
              level: m[1].length,
              text: m[2].trim(),
              lineStart: cursor,
              lineEnd: lineEndExclusive,
            });
          }
        }
        cursor = lineEndExclusive;
        if (nl === -1) break;
      }
      return out;
    }
  • The readNote helper function that reads a note's content from disk given a vault path and relative path, used by the list_sections handler to load the file.
    export async function readNote(
      vaultPath: string,
      relativePath: string,
    ): Promise<string> {
      const fullPath = await resolveVaultPathSafe(vaultPath, relativePath);
      try {
        return await fs.readFile(fullPath, "utf-8");
      } catch (err) {
        if ((err as NodeJS.ErrnoException).code === "ENOENT") {
          throw new Error(`Note not found: ${relativePath}`);
        }
        throw err;
      }
    }
Behavior3/5

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

Annotations already provide readOnlyHint=true and idempotentHint=true, so the description adds limited behavioral insight beyond stating the output structure (tree with depth). It does not contradict annotations.

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 two sentences, no wasted words, and directly conveys the purpose and use case.

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

Completeness5/5

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

Given no output schema, the description explains the return format (tree of paths with depth) and the tool's utility. The single parameter is well-covered by the schema.

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 coverage is 100% with the `path` parameter having a clear description. The tool description does not add additional semantics beyond what the schema provides.

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 'List all headings in a note as a tree of paths (with depth)', specifying the verb and resource. It also distinguishes from siblings by mentioning its use for discovering `section` arguments for other 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 explicitly states it is 'useful for discovering valid `section` arguments before calling get_note, update_section, or insert_at_section', providing clear context for when to use it. However, it does not explicitly mention when not to use it.

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

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