The Northern Ireland international, 25, still had 18 months remaining on his previous deal at The Riverside.
Former Manchester United and Sunderland centre-back McNair is closing in on 100 appearances for Boro since he made the move to Teesside in June 2018.
"We want to almost build a team around Paddy. He has excelled this season," said Boro boss Neil Warnock.