Well, you're in luck on one front - the MA marriage license apparently *does* list gender. (My license from CT does not!) So if you can get it filled out with different gender markers for each of you, that should suffice for federal purposes as well; federal policy is that a marriage reflects the genders listed on the contract [license] even if one party later transitions. That I *can* verify, as I'm in exactly the same position of arguing that a once-heterosexual marriage remains federally valid despite living in a same-sex marriage state and having matching legal genders of the partners now.
I believe, but am less certain about, that the SSA is the final arbiter when it comes to determining gender at time of marriage. How you'd get the specific clerk to recognize that, though... it may be worth venue-shopping, as different towns/counties still have different requirements (within the state legal framework, obviously).