The Northern Ireland international had 18 months left on his previous contract with the club.
Now he has signed an extension that will keep him there until the 2023/2024 season concludes.
The 25-year-old has played close to 100 games for the club since arriving in the summer of 2018.
McNair is key for Boro in central defence, and is one of several players to recently renew his deal.
"It's another step in the right direction for the club," said manager Neil Warnock to the club website.
"We want to almost build a team around Paddy.
"He has excelled this season, and he's loving every minute of it. It took him two seconds to agree to a new contract which I thought was fantastic.
"I'm absolutely delighted and this is another important step for the club for the future."