You may find this helpful for understanding intention. This document is about Holy Orders, but also applies in general with regards to intention.
On the Nullity of Anglican Orders (1896) of Pope Leo XII:33. With this inherent defect of “form” is joined the defect of “intention” which is equally essential to the Sacrament. The Church does not judge about the mind and intention, in so far as it is something by its nature internal; but in so far as it is manifested externally she is bound to judge concerning it. A person who has correctly and seriously used the requisite matter and form to effect and confer a sacrament is presumed for that very reason to have intended to do
(intendisse) what the Church does. On this principle rests the doctrine that a Sacrament is truly conferred by the ministry of one who is a heretic or unbaptized, provided the Catholic rite be employed. On the other hand, if the rite be changed, with the manifest intention of introducing another rite not approved by the Church and of rejecting what the Church does, and what, by the institution of Christ, belongs to the nature of the Sacrament, then it is clear that not only is the necessary intention wanting to the Sacrament, but that the intention is adverse to and destructive of the Sacrament.
papalencyclicals.net/Leo13/l13curae.htm
Fr. Luis Ladaria explains:** Right intention is the intention to do what the Church wants, what Christ wants
** Even non-Catholics can validly administer Baptism. In every case, however, it is the Baptism of the Catholic Church, which does not belong to those who separate themselves from her but to the Church from which they have separated themselves (cf. Augustine,
On *Baptism *1, 12,9). This validity is possible because Christ is the true minister of the sacrament: Christ is the one who truly baptizes, whether it is Peter or Paul or Judas who baptizes (cf. Augustine, *Treatise on the Gospel of John *VI,1,7; cf. CCC n. 1127). The Council of Trent, confirming this tradition, defined that Baptism administered by heretics in the name of the Father, the Son and the Holy Spirit, with the intention of doing what the Catholic Church does is true Baptism (cf. DH 1617).
ewtn.com/library/theology/mormbap1.htm