In this paper we study equations of magnetic hydrodynamics with a stress tensor. We interpret this system as the generalized Euler equation associated with an Abelian extension of the Lie algebra of vector fields with a nontrivial 2-cocycle. We use the Lie algebra approach to prove the energy conservation law and the conservation of cross-helicity.