update_memory
Update an existing memory entry by key, modifying its content, tags, or importance score for better recall and organization.
Instructions
Update the content, tags, or importance of an existing memory by key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The memory key to update | |
| new_content | No | Replacement content (omit to keep existing) | |
| tags | No | New tag list — replaces existing tags | |
| importance | No | New importance score 1-10 |
Implementation Reference
- src/index.ts:238-261 (handler)Main handler for the 'update_memory' tool. Extracts key, new_content, tags, and importance from arguments, validates that the key exists, builds the updates object (using autoTags/autoImportance helpers), calls store.update(), and returns a formatted result.
case 'update_memory': { const key = String(a['key'] ?? '').trim(); if (!key) return err('key is required'); const existing = store.byKey(key); if (!existing) return ok(`No memory found with key "${key}".`); const updates: Partial<Pick<Memory, 'content' | 'tags' | 'importance'>> = {}; if (a['new_content'] !== undefined) updates.content = String(a['new_content']).trim(); if (Array.isArray(a['tags'])) { updates.tags = autoTags(updates.content ?? existing.content, a['tags'] as string[]); } if (a['importance'] !== undefined) { updates.importance = autoImportance(updates.content ?? existing.content, Number(a['importance'])); } const updated = store.update(key, updates); return ok( `Memory updated: ${key}\n` + ` Content: ${updated!.content}\n` + ` Tags: ${updated!.tags.join(', ') || '(none)'}\n` + ` Importance: ${updated!.importance}/10` ); } - src/index.ts:91-107 (schema)Tool registration with inputSchema defining the 'update_memory' tool's parameters: key (required string), new_content (optional string), tags (optional array of strings), importance (optional number).
name: 'update_memory', description: 'Update the content, tags, or importance of an existing memory by key.', inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'The memory key to update' }, new_content: { type: 'string', description: 'Replacement content (omit to keep existing)' }, tags: { type: 'array', items: { type: 'string' }, description: 'New tag list — replaces existing tags', }, importance: { type: 'number', description: 'New importance score 1-10' }, }, required: ['key'], }, }, - src/index.ts:23-24 (registration)The tool is registered via ListToolsRequestSchema handler which returns the tools array including 'update_memory'. The tools are defined as part of the MCP server's tool list.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ - src/store.ts:62-68 (helper)The MemoryStore.update() method that performs the actual data mutation: finds memory by key, merges updates, sets updatedAt timestamp, persists to disk atomically, and returns the updated memory.
update(key: string, updates: Partial<Pick<Memory, 'content' | 'tags' | 'importance'>>): Memory | null { const idx = this.data.memories.findIndex(m => m.key === key); if (idx === -1) return null; this.data.memories[idx] = { ...this.data.memories[idx], ...updates, updatedAt: new Date().toISOString() }; this.persist(); return this.data.memories[idx]; } - src/auto.ts:14-25 (helper)autoTags helper used by the update handler to auto-detect tag categories from content (preserving user-provided tags).
export function autoTags(content: string, provided: string[]): string[] { const lower = content.toLowerCase(); const tags = new Set(provided.map(t => t.toLowerCase().trim()).filter(Boolean)); for (const [category, signals] of Object.entries(SIGNALS)) { if (signals.some(s => lower.includes(s))) { tags.add(category); } } return Array.from(tags); }