As I know, in the MCU, the Ancient One who instructed Doctor Strange was extremely powerful, an immortal, and she can see the future; she was the guardian of the Earth... so why did she not stop Thanos from coming? With some planning, she could've stopped him, either with help, or by herself. So is there any reason? Or it was forced by the author?
I believe there are two main reasons for this. Firstly, the Sorcerers protect the Earth, and world, from more mystical threats. Whilst one could argue that Thanos with the full Infinity Gauntlet is mystical, I don’t think they mean mystical like that. At the very heart of it Thanos’ threat is still very physical in nature... for the Avengers to deal with. The Sorcerers seem to protect more again other dimension level threats.
Stephen Strange: When do you start telling me what we are?
Wong: While heroes like the Avengers protect the world from physical dangers, we sorcerers safeguard it against more mystical threats.
Secondly, she knows that Doctor Strange ”was meant to be the best of us”. She’s looked into his possible futures and knows this, likely in part due to his dealings against Thanos. It seems she may leave some things to play out as they are meant to than get involved before needing to.
The Ancient One: I never saw your future, only its possibilities. You have such a capacity for goodness. You've always excelled, but not because you crave success but because of your fear of failure.
And of course she can’t exactly protect the Earth from mystical threats if she’s off world trying to take down Thanos. And that’s even before you start thinking about whether or not she could get to him in another galaxy... can the sling ring even go that far or would she even be able to use it to go somewhere unknown?
The Ancient One: I’ve spent so many years peering through time looking at this exact moment, but I can’t see past it. I’ve prevented countless, terrible futures, and after each one, there’s always another, and they all lead here, but never further.
Dr. Stephen Strange: You think this is where you die.
Doctor Strange, 2016
The Ancient One doesn't do anything about Thanos because she doesn't know about him. He only turns up after she's died, and she can't see the future past that point.