Traditionally poor travellers in this tournament, the reigning French Top 14 champions leaked three penalties to Jimmy Gopperth before a converted try from Rory Kockott gave them a shot in the arm before the interval.
But Castres crucially failed to turn pressure into points in the third quarter and with centre Remi Lamerat in the sin-bin, McGrath wrestled free to grab the game's decisive score in the 62nd minute.
Gopperth converted and tagged on a fourth penalty and frustrated Castres suffered a second sin-binning in the closing stages - replacement scrum half Julien Tomas saw yellow for a succession of crooked feeds.
Led out by Fergus McFadden and Kevin McLaughlin on their 100th appearances, Leinster quickly set about testing the French side's defence.
There was a welcome blast of sunshine for the kick-off, replacing the earlier heavy rain, and Gopperth capped off a similarly bright opening for his side with a third minute penalty.
Rob Kearney did well to hack on a Gopperth cross-field kick before Castres broke from deep, Kockott and centres Remi Lamerat and Romain Cabannes all featuring in a rare free-flowing attack from the French outfit.
But, for the most part, Leinster controlled the opening half hour's play and an offside decision allowed Gopperth to make it 6-0 in the 12th minute.
The New Zealander's third successful penalty rewarded a solid home scrum which included young tighthead Martin Moore, and Kockott snatched badly at his first chance to respond.
However, the hosts were unable to make the most of a typically thunderous burst from Sean O'Brien, and a couple of midfield turnovers that followed.
Castres made them pay with an opportunist try from Kockott in the 33rd minute, the scrum-half streaking away down the blindside after a wheeling scrum and a well-timed feed from Antonie Claassen.
McFadden was left isolated as the visitors executed a two-on-one break and Kockott confidently knocked over the 40-metre conversion to close the gap to 9-7.
Gopperth missed a penalty effort before half-time and Castres, with replacement prop Saimone Taumoepeau making an impact up front, restarted in fine fettle.
Full-back Brice Dulin gathered his own chip and had to be hauled down in the Leinster 22, and Tales' dinked kick just went over the end line as Geoffrey Palis chased it down.
The addition of Karena Wihongi further boosted the Castres scrum and their dominance of the third quarter should have led to points, but Kockott sent a long range penalty wide.
Leinster relieved the pressure as Luke Fitzgerald and David Kearney got ball in hand, the latter being the victim of a 'no arms' tackle from Lamerat that saw the Castres centre sin-binned.
Fourteen-man Castres showed no signs of wilting, but a tenacious turnover from replacement Eoin Reddan launched Leinster forward and needed no second invitation.
McFadden drew a defender to release David Kearney on the left and his brother Rob got involved in the Castres 22, before McGrath broke Wihongi's initial tackle and crashed over beside the right hand post.
Gopperth's conversion gave Leinster some much needed breathing space at nine points up, and the man-of-the-match completed his 14-point tally as Matt O'Connor's men remained workmanlike - if unspectacular - until the end.
They needed to be resolute in defence late on as despite losing Tomas in the 70th minute, Castres almost landed a losing bonus point with TMO Graham Hughes ruling out a lunge at the line from Pedrie Wannenburg who was adjudged to be inches short.