The England ‘C’ international joins the Highwaymen having made 188 appearances for Spartans since making his debut in 2013.
The club have also announced that Kris Thackray has agreed to make his loan deal into a permanent transfer, heading in the opposite direction.
“I’m delighted to get Ryan on board,” Gray told the club website.
“He was a young midfielder when he was here five years ago and became an outstanding centre half and key player at Blyth. After his injury there, he has been very unlucky to not get back into the squad. I have no doubt in my mind once Ryan gets his confidence back he will get back to where he was and we will have another top player in our squad.
“Kris is a great lad who was hampered by a couple of injuries at unfortunate times in the season,” added Gray.
“We wish him all the very best in the future.”