update_memory
Modify existing memory entries by updating titles or content using the provided memory ID. Designed for precise memory management within the Memory MCP server.
Instructions
Update an existing memory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | Optional new content for the memory | |
| memory_id | Yes | The ID of the memory to update | |
| title | No | Optional new title for the memory |
Implementation Reference
- memory_mcp/server.py:267-292 (handler)The primary handler function for the 'update_memory' tool. It validates inputs, calls the database update method, and returns a user-friendly success or error message.def update_memory( memory_id: int, title: Optional[str] = None, content: Optional[str] = None ) -> str: """ Update an existing memory. Args: memory_id: The ID of the memory to update title: Optional new title for the memory content: Optional new content for the memory Returns: A confirmation message """ try: if title is None and content is None: return ( "Error: Please provide at least one field to update (title or content)." ) success = db.update_memory(memory_id, title, content) if success: return f"Memory {memory_id} updated successfully." return f"Memory with ID {memory_id} not found." except Exception as e: return f"Error updating memory: {str(e)}"
- memory_mcp/server.py:379-401 (schema)The schema definition for the 'update_memory' tool, registered in the list_tools handler, specifying input parameters and requirements.types.Tool( name="update_memory", description="Update an existing memory.", inputSchema={ "type": "object", "properties": { "memory_id": { "type": "integer", "description": "The ID of the memory to update", }, "title": { "type": "string", "description": "Optional new title for the memory", }, "content": { "type": "string", "description": "Optional new content for the memory", }, }, "required": ["memory_id"], "title": "updateMemoryArguments", }, ),
- memory_mcp/server.py:442-449 (handler)The dispatch handler within the generic call_tool function that routes 'update_memory' calls to the specific update_memory implementation.elif name == "update_memory": if not arguments or "memory_id" not in arguments: raise ValueError("Missing memory_id argument") memory_id = int(arguments["memory_id"]) title = arguments.get("title") content = arguments.get("content") result = update_memory(memory_id, title, content) return [types.TextContent(type="text", text=result)]
- memory_mcp/server.py:137-180 (helper)Low-level DatabaseManager helper method that executes the SQL UPDATE on the memories table.def update_memory( self, memory_id: int, title: Optional[str] = None, content: Optional[str] = None ) -> bool: """Update an existing memory's title or content.""" if not self.conn: self.initialize_db() if self.conn is None: raise RuntimeError("Database connection not available") # First check if the memory exists existing_memory = self.get_memory_by_id(memory_id) if not existing_memory: return False # Build update query update_items = [] params: List[Any] = [] if title is not None: update_items.append("title = ?") params.append(title) if content is not None: update_items.append("content = ?") params.append(content) if not update_items: return True # Nothing to update # Add updated_at timestamp update_items.append("updated_at = ?") params.append(datetime.datetime.now().isoformat()) # Add memory_id to params params.append(memory_id) # Execute update self.conn.execute( f"UPDATE memories SET {', '.join(update_items)} WHERE id = ?", params ) self.conn.commit() return True