This paper addresses safe motion planning for a manipulator, in environments shared with human operators. We formulate the problem as an optimal control problem for a hybrid system integrating three different operation modes: nominal, soft safety, and hard safety. The manipulator is assigned a nominal trajectory to reach a target position. If no human is present, then, the manipulator tracks the nominal trajectory; if a human enters its workspace, it tries to avoid it but without adopting too sharp and abrupt actions, except when strictly needed for safety. The decision on when and to what mode to commute is taken online, via a model predictive control approach involving a constrained optimization program with binary variables setting the active/nonactive status of the operating modes. The resulting control input is applied in a receding horizon fashion and the nominal trajectory towards the target is re-computed based on the current state of the system. The proposed approach is applied to a realistic simulation environment and appears computationally feasible and promising.