update_section
Modify or append content to a specific section of a memory document using Markdown formatting. Supports headings, bold, italic, code, links, lists, and tables for structured updates.
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
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The new content for the section. Supports full Markdown: headings (#), **bold**, *italic*, `code`, [links](url), ```code blocks```, lists, tables, etc. | |
| memory_id | Yes | The ID of the memory document to update | |
| mode | No | Whether to append to or replace the section content (default: append) | |
| section | Yes | The section name to update |
Input Schema (JSON Schema)
{
"properties": {
"content": {
"description": "The new content for the section. Supports full Markdown: headings (#), **bold**, *italic*, `code`, [links](url), ```code blocks```, lists, tables, etc.",
"type": "string"
},
"memory_id": {
"description": "The ID of the memory document to update",
"type": "string"
},
"mode": {
"description": "Whether to append to or replace the section content (default: append)",
"enum": [
"append",
"replace"
],
"type": "string"
},
"section": {
"description": "The section name to update",
"type": "string"
}
},
"required": [
"memory_id",
"section",
"content"
],
"type": "object"
}
Implementation Reference
- src/tools/updateSection.ts:4-72 (handler)The main execution handler for the 'update_section' tool. Validates input parameters, interacts with StorageManager to update the memory section (append or replace), checks if section existed, computes stats, and returns a formatted 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/types/memory.ts:61-66 (schema)TypeScript interface defining the input parameters for the update_section tool handler.export interface UpdateSectionParams { memory_id: string; section: string; content: string; mode?: 'replace' | 'append'; }
- src/index.ts:141-170 (registration)Tool registration in the ListTools handler, defining name, description, and inputSchema for 'update_section'.{ 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 logic in the CallTool handler that routes 'update_section' calls to the updateSectionTool function.case "update_section": return await updateSectionTool(storageManager, args);
- Core helper method in StorageManager that parses sections, updates or creates the target section based on mode (append/replace), rebuilds the Markdown content, and persists the changes 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); }