The best advice for any author is "write what you know" and most authors know themselves better than anyone else (or at least they should; abject lack of self-awareness doesn't often accompany good writing skills). Consequently, most well-written, well-rounded protagonists are based at least partially on the author's own life experiences, fears, loves, etc. combined with his or her observations of other people along with a healthy dose of imagination.
When a person (usually a non-writer) says that a Mary Sue (or her male counterpart, Gary Stu) is the inevitable result of an author inserting him- or herself into a story ... that's pretty clearly bullshit from the "write what you know" standpoint. And unhelpful bullshit at that; I've heard from many a beginning writer who got completely stuck on a story because he or she felt it was somehow wrong to write about personal experiences in fiction, for fear of creating a dreaded Mary Sue.
The term "Mary Sue" comes from Paula Smith's 1973 Star Trek parody "A Trekkie's Tale." The story features 15-year-old Lieutenant Mary Sue as a send-up of all the adolescent wish-fulfillment fantasies that Smith had seen in Trek fan fiction.
The problem with a Mary Sue isn't that she's based on the author. The problem with a Mary Sue is that she's unrealistically flawless: the author can't imagine anyone better than Mary Sue ... and consequently she's dull as dirt. She's pure wish-fulfillment without any regard to what makes for an interesting, growth-worthy character and compelling conflict.
Mary Sue is often a teen prodigy. She's beautiful. She's super-smart. Her hair and eyes are a rare color. Her clothes are fabulous. She had a tragic childhood in an exotic country but emerged plucky and upbeat (and probably inherited a lot of money in the process). She excels at everything she tries: cheerleading, singing, horseback riding, gymnastics, mathematics, piloting, martial arts. She's the first to figure out the puzzle and she wins every fight.
There isn't any compelling conflict in a story with a Mary Sue protagonist because there's never any real question as to who will be victorious: Mary Sue will. Immediately. Without mussing up her hair. So dull.
There are several Mary Sue quizzes around on the Web to help you determine whether you've got a Sue on your hands; some are better than others. From my perspective, the key to avoiding creating a Mary Sue, even in superhero fiction, is to focus on making a character who's believable within the world you've created.
It's a given that your character is probably going to be an above-average person, particularly if you're writing a fantasy, and that's fine: the key is to make sure your character has interesting flaws* he or she is trying to work around or overcome as well. If your character had a genuinely tragic childhood, chances are good that he or she will be carrying around some emotional baggage that makes her less than upbeat and plucky all the time (but try to avoid excess teen angst, because Angsty Sues are just as annoying as Mary Sues. Remember: interesting flaws, not annoying ones). If your character is super-good at gymnastics, chances are that he won't be much good at puzzles. And if he's good at both, he's probably hyper-focused and perfectionist and spends a lot of time with his books and pommel horse and not a lot of time with other people. Consequently he doesn't have a lot of friends, doesn't have a lot of patience for people he sees as less capable than himself, and generally doesn't know how to play well with others.
Always remember: good conflict emerges from character interactions, and characters should be changed by the conflicts they survive.
* Character "flaws" can be largely subjective, and situational. Every character trait has potential positives and negatives. For instance, being energetic is usually thought of as a good thing, right? Consider a naturally-energetic, intelligent character who is good at sports and can hunt zombies for 36 hours straight ... but who also finds it difficult to sit still for long periods, and consequently he doesn't have much of a clue about computers and doesn't read books. He may have convinced himself that reading isn't that important ... until the day he's desperately got to send a message to his team, and all he's got is a malfunctioning PC, and for the first time in his life he's got to RTFM or he's dead.
The dark side of self-confidence is arrogance; for prudence, it's cowardice; for persistence, it's stubbornness, etc. It may help to think of characters as having traits that help them achieve their goals within a story along with traits that will complicate/hamper their efforts rather than focusing on "flaws" per se.