See a thread https://discussions.apple.com/thread/250414800?
You have to sign Apple ID and password of iPhone from a web browser at www.icloud.com ( in case if different Apple ID and password are signed in Mac and iPhone on the same network .
Read Resolve duplicates while importing contacts into Contacts on Mac - Apple Support
If same Apple ID and password are signed on both device .
Take help of a web browser and enter in www.icloud.com with the apple id and password used in an iPhone , the contacts that were saved in will be visible select the desired contacts and click on gear icon in the left bottom corner and click on export as v card .
Â
Open finder , click on downloads , right click on .vcf file and open with contacts .app( default ) .
Â
The address book will get opened , a pop up window will appear stating are you sure you want to add number of cards , click on add .
Â
Again open your address book the contacts that were in the iPhone will be transferred under the section “ All contacts “ in the Mac address book .
Â
Sign out from www.icloud.com used with Apple ID and password for an iPhone .
Â
Then enter in www.icloud.com with the apple id and password used in the Mac , click on gear icon and click on import as v card all the contacts will be transferred in the iCloud server , click on create group on the bottom right corner an untitled folder will be created in the side bar and the contacts from iPhone are transferred to the iCloud server account .
Â
See some articles iCloud: Export a contact as a vCard from iCloud Contacts
iCloud: Import a contact into iCloud Contacts
iCloud: Create a group in iCloud Contacts
Note : if there is list of old contacts ( they can be in groups ) , in old version of Mac " on my Mac section " was active in contact preferences , you can select ( use command and A keys ) copy ( use command and C keys ) and paste ( use command and V keys ) them in " All iCloud " ( applicable when same Apple ID and password is signed in Mac / iPhone ) .