The 23-year-old academy gradate was due to be out of contract at the end of the month and had been attracting interest from elsewhere. However, he put to bed any doubt that he would not be a Cobbler next season by signing a contract that will keep him at Sixfields until 2024.
"I'm delighted to get it sorted," said McWilliams. “It took a little while but we got there in the end.
"There's obviously two parties involved in the negotiations and we wanted to make it right but now it's happened.
"I'm happy with the progress I've made here and I just see this place (Sixfields) as my home and I love playing here every week.
"I spoke with the gaffer and we all want to go in the same direction and that’s up. We want to put things right after how last season ended.
"It still stings a little bit but you have to put it to bed and enjoy the summer. The summer has been short and sweet and now we are back at it and we're ready to go again.”
This time last week, Cobblers had not made any signings and were at risk of losing three key players in Fraser Horsfall, Liam Roberts and McWilliams.
But a week is a long time in football and whilst Roberts has left for Middlesbrough, Town look to be in good shape for the start of pre-season with four players recruited and McWilliams signed on for another two years.
The players were back in for pre-season testing on Wednesday and Thursday and will head down to their training base at Moulton on Friday.
"I've kept myself in good nick,” added McWilliams. “I like to think I'm quite a fit lad anyway so I don't think I will be too far off.
"I think the club is appealing to players after what happened last season and most people who come here and speak to the staff will know we are heading in the right direction.
"It’s good to see a few new lads come in and we also have plenty who were here last season so it's about gelling in pre-season and before you know it the season will be here so we got to make sure we are ready.
"The team spirit was great last season and I've missed the boys but now pre-season is on the way and I'm looking forward to meeting the new boys and making some new memories."