add_to_list
Add structured data items to specific sections of a memory document, enabling agents to systematically organize and update project knowledge over time.
Instructions
Add an item to a list section in a memory document
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item | Yes | The item data to add (structure depends on template) | |
| memory_id | Yes | The ID of the memory document to update | |
| section | Yes | The section name to add the item to |
Input Schema (JSON Schema)
{
"properties": {
"item": {
"description": "The item data to add (structure depends on template)",
"type": "object"
},
"memory_id": {
"description": "The ID of the memory document to update",
"type": "string"
},
"section": {
"description": "The section name to add the item to",
"type": "string"
}
},
"required": [
"memory_id",
"section",
"item"
],
"type": "object"
}
Implementation Reference
- src/tools/addToList.ts:5-43 (handler)The main handler function `addToListTool` for the 'add_to_list' tool. It validates input parameters, reads the target memory document and section, formats the new item, appends it to the section using StorageManager, and returns a success message with the formatted item.export async function addToListTool( storageManager: StorageManager, args: any ): Promise<any> { const params = args as AddToListParams; if (!params.memory_id || !params.section || !params.item) { throw new Error('memory_id, section, and item are required'); } // Read the memory document const memory = await storageManager.readMemory(params.memory_id); if (!memory) { throw new Error(`Memory document '${params.memory_id}' not found`); } // Find the section const section = storageManager.findSection(memory.content, params.section); if (!section) { throw new Error(`Section '${params.section}' not found in memory document '${params.memory_id}'`); } // Format the item using generic formatting const itemText = formatGenericItem(params.item); // Add the item to the section await storageManager.updateSection(params.memory_id, params.section, itemText, 'append'); return { content: [{ type: 'text', text: `Successfully added item to ${params.section} in memory document '${params.memory_id}': ${itemText} The item has been appended to the section. You can view the updated section using the get_section tool.` }] }; }
- src/types/memory.ts:36-40 (schema)TypeScript interface `AddToListParams` defining the input parameters for the add_to_list tool: memory_id (string), section (string), item (object). Used for type validation in the handler.export interface AddToListParams { memory_id: string; section: string; item: Record<string, any>; }
- src/index.ts:59-81 (registration)Registration of the 'add_to_list' tool in the MCP server's ListToolsRequestHandler. Defines the tool name, description, and JSON inputSchema matching AddToListParams.{ name: "add_to_list", description: "Add an item to a list section in a memory document", 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 add the item to", }, item: { type: "object", description: "The item data to add (structure depends on template)", }, }, required: ["memory_id", "section", "item"], }, },
- src/index.ts:262-263 (registration)Dispatch logic in CallToolRequestHandler switch statement that routes 'add_to_list' calls to the addToListTool handler.case "add_to_list": return await addToListTool(storageManager, args);
- src/tools/addToListHelpers.ts:32-77 (helper)Key helper function `formatGenericItem` called by the handler to convert the input item object into formatted Markdown text (with title, stars, bullet points) before appending to the list section.export function formatGenericItem(item: Record<string, any>): string { if (typeof item === 'string') { return `- ${item}`; } if (typeof item === 'object' && item !== null) { // Look for common title fields const titleFields = ['name', 'title', 'destination', 'company', 'activity']; let title = ''; for (const field of titleFields) { if (item[field]) { title = String(item[field]); break; } } if (title) { // Format with star rating if present const stars = formatStarRating(item.rating || item.stars); let result = `### ${title}${stars}\n`; // Convert remaining fields to field list format const remainingFields: Record<string, string> = {}; for (const [key, value] of Object.entries(item)) { if (!titleFields.includes(key) && key !== 'rating' && key !== 'stars' && value) { remainingFields[key] = String(value); } } result += formatFieldList(remainingFields); return result; } else { // Simple key-value format without title const fields: Record<string, string> = {}; for (const [key, value] of Object.entries(item)) { if (value) { fields[key] = String(value); } } return formatFieldList(fields); } } return `- ${String(item)}`; }