McHugh was called up to the major leagues on August 22, 2012, and he made his MLB debut on August 23 against the Colorado Rockies at Citi Field. He pitched seven scoreless innings and got nine strikeouts while surrendering two hits and a walk. Despite his performance, McHugh did not get the win as the Mets lost, 1–0. McHugh made two more starts before being demoted on August 24 to make room on the roster for Jeremy Hefner. Overall with the 2012 Mets, he appeared in eight games compiling an 0–4 record with a 7.59 ERA. During 2013, McHugh made three appearances with the Mets; he had a 10.29 ERA and an 0–1 record.
On December 18, 2013, McHugh was claimed off waivers by the Houston Astros. In 2014, he finished with 11 wins and led the team in ERA, with a 2.73 mark. In 2015, McHugh finished 2nd in the American League in wins with 19, behind teammate Dallas Keuchel's 20 wins. In 2016, he pitched in a career-high 33 starts, finishing 13–10 with an ERA of 4.34 in innings. McHugh began the 2017 season on the 10-day disabled list due to tendonitis in his right shoulder. On April 6, 2017, he left a game while on rehab assignment with the Triple-AFresno Grizzlies after feeling tightness in his elbow and biceps. With posterior impingement in his right elbow, McHugh was ruled out for an extended period of time. He was limited to just 12 starts. He appeared in two games of the postseason, pitching a combined total of six innings, allowing a total of one hit and three runs. The Astros won the 2017 World Series. Three years later, the Houston Astros sign stealing scandal broke, in which it was revealed that the Astros had cheated during their championship season. McHugh said that he knew about the sign stealing scheme and expressed remorse for going along with it. McHugh made the transition to a relief role in 2018, appearing in 58 games. He finished with an ERA of 1.99 in innings, striking out 94. In 2018, he had the third-lowest swing rate for his in-strike-zone sliders of any pitcher in baseball, behind only Aroldis Chapman and Robert Stock. McHugh began the 2019 season as a starting pitcher for the Astros, a job he secured in spring training. He was demoted to the bullpen on May 11, 2019, after eight starts. At the time of his demotion, he had registered an ERA of 6.37 in 41 innings. Overall with the 2019 Astros, McHugh appeared in 35 games while recording 82 strikeouts in innings with a 4.70 ERA and a 4–5 record. On October 31, 2019, McHugh elected to become a free agent.
On March 5, 2020, McHugh signed a one-year contract with the Boston Red Sox. On July 19, 2020, the team announced that he would not play during 2020, noting that McHugh's "elbow was not responding as he had hoped" following a non-surgical procedure during the offseason. He was added to the team's restricted list on July 23.
McHugh married longtime girlfriend Ashley Buzzy in 2009 in Athens, Georgia. The couple welcomed their first child, a son named Elder, in December 2015. In 2019, McHugh started a podcast called "The Twelve Six Podcast" where he interviewed other MLB players to bring out the human side of baseball.