I have only heard it to refer to Federal agents, not state or local, and specifically back in the first half of the twentieth century when the federal government was fighting organized crimes. There were a lot of movies back then that had g-men in them.
Uncle Sam is the government.
I can say, "I don't want Uncle Sam restricting my internet access."
I can not say "I'm from Uncle Sam. Nice to meet you."