The machining accuracy is mainly indicated by the contour error especially in high-precision processing. Previously, scholars have proposed many controllers to reduce contour errors in real-time machining, such as the cross coupling controller and sliding mode controller. In this paper, we propose a controller based on model predictive control (MPC), and the contour error caused during path tracking can be effectively reduced by this controller. First of all, for two-dimensional (2D) and three-dimensional (3D) tool paths, their contour errors are deduced based on coordinate system transform. Second, the MPC-based controller is designed with the state-space discrete model of a machine tool. The contour error is regarded as a constraint during receding optimization. These are reasons why the presented control scheme is adapted with both bi-axis and three-axis machine tools. Furthermore, in order to improve the efficiency of receding optimization, the contour error of a 3D curve is simplified. Subsequently, the optimization problem is transformed into the standard form of quadratic programming. Finally, a 2D tool path and a 3D tool path are machined to test the proposed controller. Simulations and experiments show satisfactory results which indicate effectiveness of the proposed method.