What do you mean by "go to Tokyo as a boy"? Is this about a person who can freely change their gender every day? If such a context has been already set up, 男の子で東京に行く might make sense, but otherwise it's a puzzling sentence.
it seems both で and に can mean "as" in certain contexts. So how do you distinguish between those
に is a role marker. If your "as" means "serving as" or "functioning as", you can use に.
- お土産に絵葉書を買う
to buy a postcard as a souvenir
- お礼に手紙を送る
to present flowers as a token of gratitude
- 仕上げにパセリを乗せる
to add parsley as a finishing touch
で is a condition/scope/reason/method marker, and it corresponds to various English prepositions ("in", "at", "by", "with", ...) depending on the situation. You cannot expect one-to-one correspondence with English prepositions at all, so you need to remember the correct usage individually. See this: Does で in this sentence 「日本の昔話は代表的なものだけで、2,3百はあります。」 mean that the noun before it is a tool for the proceding sentence?
Provided that this person has the special ability to change gender, 男の子で東京に行く makes sense (it describes their state when going to Tokyo), but 男の子に東京に行く makes no sense ("serving as a boy" means nothing here).
Related: https://japanese.stackexchange.com/a/17763/5010