This is a matter of style, not grammar. Depending on what source you refer to, you will get different guidance.
The following is what The Chicago Manual of Style (17th ed.), 6.52, says on the subject:
The adverbs too and either used in the sense of “also” generally need not be preceded by a comma.
I had my cake and ate it too.
Anders likes Beethoven; his sister does too.
The airport lacked charging stations; there were no comfortable chairs either.
When too comes in the middle of the sentence or clause, however, a comma aids comprehension.
She, too, decided against the early showing.
Personally, that's the advice I follow. In the past, I would put a comma before a final too in a sentence, but I've since changed that style.
However, doing it differently is certainly not incorrect.
Like when using a pronoun, the context of its use can be ambiguous. If you find that something is ambiguous, you can use different punctuation (perhaps adding a comma or removing it makes the meaning more clear) or you can rephrase the sentence altogether.