Trajectory planning and obstacle avoidance play essential roles in the cooperative flight of multiple unmanned aerial vehicles (UAVs). In this paper, a unified framework for onboard distributed trajectory planning is proposed, which takes full advantage of intelligent discrete and continuous search algorithms. Firstly, the Monte Carlo tree search (MCTS) is used as the task allocation algorithm to solve the cooperative obstacle avoidance problem. Taking the task allocation decisions as the constraint, knowledge-based particle swarm optimization (Know-PSO) is used as the optimization algorithm to solve the onboard distributed cooperative trajectory planning problem. Simulation results demonstrate that the proposed intelligent MCTS-PSO search framework is effective and flexible for multiple UAVs to conduct the cooperative trajectory planning and obstacle avoidance. Further, it has been applied in practical experiments and achieved promising results.