The former Frasier star played the character in 2006's X-Men: The Last Stand.
A source close to the production on director Bryan Singer's new film says, "It wasn't hard to get him to sign on for a guest appearance. He jumped at the opportunity the second it was brought to his attention.
"Kelsey's special cameo was secretly shot during post-production on the Fox (studio) lot under the impression that Kelsey would be on set to film a pilot for a different project."
The news comes a day after Singer took to Twitter.com to shoot down reports suggesting Halle Berry's scenes as mutant Storm had been cut from the new film.