The gait generation algorithm considering both step distance adjustment and step duration adjustment could improve the anti-disturbance ability of the humanoid robot, which is very important to the dynamic balance, but the step duration adjustment often brings non-convex optimization problems. In order to avoid this situation and improve the robustness of the gait generator, a gait generation mechanism based on flexible model predictive control is proposed in this article. Specifically, the step distance adjustment and step duration adjustment are set to be optimization objectives, while the change of pressure center is treated as the optimal input to minimize those objectives. With the current system state being used for online re-optimization, a feedback gait generator is formed to realize the strong stability of variable speed and variable step distance walking of the robot. The main contributions of this work are twofold. First, a gait generation mechanism based on flexible model predictive control is proposed, which avoids the problem of nonlinear optimization. Second, a variety of feasible optimization constraints were considered, they can be used on platforms with different computing resources. Simulations are conducted to verify the effectiveness of the proposed mechanism. Results show that as compared with those considering step adjustment only, the proposed method largely improves the compensation ability of disturbance and shortens the adjustment time.