In the speech that McCarthy made, he claimed to have close personal knowledge of many Soviet spies working within the American federal government. His speech ALSO occurred within the context of the cold war, (basically communists verus capitalists, soviets vs americans it was very heated and controlled a lot of politics.)
McCarthy struck fear into the people, due to so many fearing the rise of communism and his allegations of Soviets (communist) spies infultrating the government severely alarmed and scared everyone. This slowly led to what we call the Second Red Scare, where people were falsely accused of being communist without proper evidence.
So basically, I would say his purpose was to scare people. And I come to that conclusion based on everything I have said he has done above.
Additionally, here is a summary for your reference complimentary of my AI, who did background research on the topic and made a short summary from it. It is mainly about the background of McCarthy.
McCarthy was born in 1908 near Appleton, Wisconsin. He was elected to the U.S. Senate in 1944 and served two terms. McCarthy gave his Enemies from Within Speech during the Cold War. His investigations focused on rooting out communists; he never charged a single person.
(There is more, but I cut it short. if you do need more if you are doing background research on him let me know)