Skip to main content
Glama

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

NameRequiredDescriptionDefault
itemYesThe item data to add (structure depends on template)
memory_idYesThe ID of the memory document to update
sectionYesThe 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

  • 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.` }] }; }
  • 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);
  • 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)}`; }

Other Tools

Related 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