It was foreign, but they sinicized and they claimed to be representatives of Chinese civilization, so in the course of history it was eventually accepted that they were legitimate successors. This is in contrast to imperial Japan, which explicitly did not claim to be a successor of Chinese civilization, which was one of the reasons why they continued to be viewed as foreign.