McCartney, 30, previously spent two years at Upton Park between 2006-2008, making 71 appearances.
The Northern Irishman told West Ham's website: "It is brilliant to be coming back. For me personally it will be great to be playing again for a club like West Ham.
"It is a big opportunity for me and I can't wait to get started again. I am looking forward to being part of the manager's squad and the club's push for promotion."
"I have got experience of the Championship. It is a tough league to be in but with the signings the manager has made already and the players already here, it is a healthy squad," McCartney added.
"In my eyes, it is more than capable of getting us up at the first attempt."
The Hammers next face a trip to Doncaster Rovers for a league fixture on Saturday.