I've mentioned this over and over, but the universe or world your character is placed in has a great deal to do with whether or not your character is a Mary Sue. In a lot of ways, making a character fit into the world they find themselves in is your plot. Take superheros, for instance. How many of them do we have running around here on Earth?
How do you put superheros to work on Earth?
You make their existence make sense. For instance, the superheros are given battle suits to fight in, or they have special training in advanced technology. Or even pseudoscience.*
Another thing you have to watch in world building are the laws of the universe. While in most case you are using the laws of our universe, and you don't need to define them. Water will be wet, air will be breathable and things you drop will fall to the floor. On occasion, however, you will defy, bend, or even break the laws of the universe as we know it. That's ok, it happens. The trick is to make sure your story works. DO what you will with the laws of the universe, just make sure you are consistent, and that your unconventional methods explain why your character works.
I think building a universe is the most difficult aspect of fixing a Mary Sue. Probably because I say universe to indicate how big of an effort that is. From who your character is to the people around that character, to the world they live on and the laws they live by.
If the world is wrong, then the character you've created is a jarring anomaly instead of a valuable piece of the puzzle. I have personally never run across a character that doesn't work, period, only characters that don't work in the universe they've been placed in after creation. That takes time though. It's best to start by writing the character and practicing making the world work around them. The better the world works, the better the story will work and the easier it will be to present the story as best suits your ambitions.
So the universe is a pretty big place, and it involves a lot. It's people, it's places, it's accepted rules. It's all the things that create a culture and a society, the things your characters take for granted and the things outsiders have to learn because everyone assumes they know what's going on when nobody really knows anything. It's the notes and half finished thoughts and scraps where you've scribbled down everything from a new word for God to a new word for a mile.
It's books filled with highlighter marks from tracking down this thought or that. It's webpages that are bookmarked and visited so frequently that they're practically your homepage. It's all these things and it centered on one concept. It's centered on the idea of making your character believable.
I was editing a friend's story and we ended up in a bit of an argument over that fact. While her character was possible and there was proof that such people exist, it was a little jarring to run across such a character in a book as a secondary character. I still think that if the character had been the main character, with the story centered on that one's pov and perspectives it would have carried, he was little more than a vague side character at the time and he was jarring and out of place there.
It might even be said that he was too much to accept given the state of things for the main character.
Before I end up rambling even more, I leave you with this.
The Mary Sue is a jarring and out of place character in most worlds, but in the right world, she can fit in just a little bit better.
Next, Mary Sue: The Conclusion
*Pseudoscience: in this case, it's fake science that pulls just enough from real science that it sounds plausible even if it's really not. Can also be used for made up information that has no bearing on real science. This should be used with caution.