Mostly, I steer clear of the Gandalf archetype. However, I have used characters that fill similar roles from a plot point. But most of them operate from some other agenda. For example, I'd say that Elrond, Galadriel, and Strider are all more common character types in my campaigns...
I think a sage advisor is a needed role in a campaign. However, most of the time, unlike Gandalf, they don't "go along" on the missions. Nor are they frequently tasked with preserving the world or any other such nonsense. Usually, they're more patrons or employers. They're there primarily as a resource, or a source of missions, but they're not "guardian angel" types.
Two exceptions:
In one of my very early D&D campaigns, Bahamut (the platinum dragon) took an interest in the PCs because of their "great potential." He had a tendency to show up and steer them on missions - acting very like Fizzban in
Dragonlance. Of course, this was BEFORE that came out, so I guess I was just creative enough to come up with it on my own. The PCs eventually found out they had basically become champions of the king of good dragons. Who had an agenda for fixing the world.
I also used Odin in that role a couple times in another campaign - taking basically the same approach as Norse myth, where he often would show up as an old beggar with a floppy hat, an eyepatch, and a staff.
My last DM tried to set up a particular wizard as our own Gandalf. We didn't take well to him after he dosed us with a truth potion so he could get "straight answers." That basically made us all VERY paranoid. So he introduced another wizard when we relocated who we liked a WHOLE lot more. He didn't drug us...
Of course, none of us were paranoid enough that we caught on to the "Evil Priestess posing as helpful" in the sequel campaign. Even the fact that it was set in
The Keep on the Borderlands didn't tip us off...
Of course, I think we were distracted by the fact that she was hot...
I prefer slightly untrustworthy advisor types. I wrote a short story about a master thief who these days makes regular appearances in my campaigns. He's semi-retired...but he's done some amazing things in his life. Basically, it's like having a character who's a cross between Strider and the Grey Mouser as a patron...
Useful, but not exactly "DM ex machina..."