Skip to main content
Glama

update_section

Modify or add content to specific sections in memory documents using Markdown formatting for structured project knowledge management.

Instructions

Update an entire section of a memory document. Content supports full Markdown formatting including headings, bold, italic, code blocks, links, lists, tables, and all standard Markdown syntax.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesThe ID of the memory document to update
sectionYesThe section name to update
contentYesThe new content for the section. Supports full Markdown: headings (#), **bold**, *italic*, `code`, [links](url), ```code blocks```, lists, tables, etc.
modeNoWhether to append to or replace the section content (default: append)

Implementation Reference

  • The updateSectionTool function implements the core logic for the update_section tool, handling input validation, memory retrieval, section existence check, update via StorageManager, response formatting with word/line counts, and success message.
    export async function updateSectionTool(
      storageManager: StorageManager,
      args: any
    ): Promise<any> {
      const params = args as UpdateSectionParams;
    
      if (!params.memory_id || !params.section || params.content === undefined) {
        throw new Error("memory_id, section, and content are required");
      }
    
      // Validate mode
      const mode = params.mode || "append";
      if (mode !== "append" && mode !== "replace") {
        throw new Error('mode must be either "append" or "replace"');
      }
    
      // Read the memory document
      const memory = await storageManager.readMemory(params.memory_id);
      if (!memory) {
        throw new Error(`Memory document '${params.memory_id}' not found`);
      }
    
      // Check if section exists
      const existingSection = storageManager.findSection(
        memory.content,
        params.section
      );
      const sectionExists = existingSection !== null;
    
      // Update the section using the storage manager
      await storageManager.updateSection(
        params.memory_id,
        params.section,
        params.content,
        mode
      );
    
      // Format response based on what happened
      let actionText: string;
      if (!sectionExists) {
        actionText = `Created new section "${params.section}" with content`;
      } else if (mode === "replace") {
        actionText = `Replaced content in section "${params.section}"`;
      } else {
        actionText = `Appended content to section "${params.section}"`;
      }
    
      // Count words/lines for feedback
      const wordCount = params.content
        .trim()
        .split(/\s+/)
        .filter((w) => w.length > 0).length;
      const lineCount = params.content.split("\n").length;
    
      return {
        content: [
          {
            type: "text",
            text: `Successfully updated memory document '${params.memory_id}':
    
    **Action**: ${actionText}
    **Content Added**: ${wordCount} words, ${lineCount} lines
    **Mode**: ${mode}
    
    The section has been updated. You can view it using the get_section tool or check the full document summary with get_memory_summary.`,
          },
        ],
      };
    }
  • src/index.ts:142-170 (registration)
    Registration of the update_section tool in the ListToolsRequestSchema handler, including name, description, and JSON input schema definition.
      name: "update_section",
      description:
        "Update an entire section of a memory document. Content supports full Markdown formatting including headings, **bold**, *italic*, `code blocks`, [links](url), lists, tables, and all standard Markdown syntax.",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "The ID of the memory document to update",
          },
          section: {
            type: "string",
            description: "The section name to update",
          },
          content: {
            type: "string",
            description:
              "The new content for the section. Supports full Markdown: headings (#), **bold**, *italic*, `code`, [links](url), ```code blocks```, lists, tables, etc.",
          },
          mode: {
            type: "string",
            enum: ["append", "replace"],
            description:
              "Whether to append to or replace the section content (default: append)",
          },
        },
        required: ["memory_id", "section", "content"],
      },
    },
  • src/index.ts:277-278 (registration)
    Dispatch handler in the CallToolRequestSchema switch statement that routes update_section calls to the updateSectionTool function.
    case "update_section":
      return await updateSectionTool(storageManager, args);
  • TypeScript interface defining the input parameters for the update_section tool, used for type casting in the handler.
    export interface UpdateSectionParams {
      memory_id: string;
      section: string;
      content: string;
      mode?: 'replace' | 'append';
    }
  • Core helper method in StorageManager that parses sections, handles append/replace logic, rebuilds Markdown content, and persists changes to file with backup.
    async updateSection(
      memoryId: string,
      sectionName: string,
      newContent: string,
      mode: "append" | "replace" = "append"
    ): Promise<void> {
      const memory = await this.readMemory(memoryId);
      if (!memory) {
        throw new Error(`Memory document '${memoryId}' not found`);
      }
    
      const sections = this.parseSections(memory.content);
      const sectionIndex = sections.findIndex(
        (section) =>
          section.name.toLowerCase() === sectionName.toLowerCase() ||
          section.name.toLowerCase().replace(/[^a-z0-9]/g, "_") ===
            sectionName.toLowerCase()
      );
    
      if (sectionIndex === -1) {
        // Section doesn't exist, add it
        const lines = memory.content.split("\n");
        lines.push("", `## ${sectionName}`, "", newContent);
        memory.content = lines.join("\n");
      } else {
        // Section exists, update it
        const section = sections[sectionIndex];
        if (mode === "append") {
          section.content = section.content
            ? `${section.content}\n\n${newContent}`
            : newContent;
        } else {
          section.content = newContent;
        }
    
        // Rebuild the content
        memory.content = this.rebuildContent(sections);
      }
    
      await this.writeMemory(memory);
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions Markdown formatting support but fails to describe critical behaviors: whether this operation requires specific permissions, if it's idempotent, what happens on invalid section names, error responses, or rate limits. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two sentences that efficiently convey the core functionality and Markdown support. It's front-loaded with the main purpose. The Markdown examples could be slightly more concise, but overall there's minimal wasted text.

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?

For a mutation tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It covers the basic operation and formatting but lacks crucial context about permissions, error handling, side effects, and what the tool returns. The absence of output schema means the description should ideally mention return values, but it doesn't.

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 parameters thoroughly. The description adds minimal value by repeating Markdown support information that's already in the 'content' parameter schema. It doesn't provide additional context about parameter interactions, constraints, or examples beyond what's in the structured schema.

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 verb 'Update' and the resource 'an entire section of a memory document', making the purpose explicit. It distinguishes from siblings like 'update_list_item' by specifying it works on document sections rather than list items. However, it doesn't explicitly contrast with 'create_memory' or 'get_section', leaving some sibling differentiation incomplete.

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 like 'create_memory' for new documents, 'get_section' for reading, or 'update_list_item' for list operations. It mentions Markdown support but doesn't specify prerequisites, error conditions, or when 'append' vs 'replace' mode is appropriate beyond the schema's default.

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/nmeierpolys/mcp-structured-memory'

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