Before you guys tell me, I know there was no "China" before the Mongols who unified it into a single country (like how there was no "Russia" until Ivan the Great.) So my statement "allowed in China centuries ago" is technically incorrect but I didn't want a super long title.
But yes, I'm very much curious of how the Chinese felt about trading with the Portuguese when the last time they dealt with foreigners was with the Mongols. And we all know what happened there.
Well, your suppositions are a bit incorrect.
I know there was no "China" before the Mongols who unified it into a single country
We can speak of the existence of a concept of a China from the first millennium BC (there's some discussion here, and a united China was definitely a political reality for many, many centuries before the Mongols. If you're thinking of the fact that China was divided before the Mongols, it's because China was invaded and lost a third of its territory to the invaders so it's not as if the concept was lost. I think you mean to say that China has not been divided for more than a century ever since the Mongol conquest (although de facto division lasting a few decades has happened, such as amidst the chaos of the 17th century), but I repeat that that does not mean China did not exist or was not unified before then.
the last time they dealt with foreigners was with the Mongols
The Ming government in the 16th century dealt with foreigners in the capital on a regular basis due to tribute missions, which was especially important during the Ming because the Ming were especially insistent on tribute trade rather than private trade. The best-known and considered the most civilized were the Koreans of the Joseon dynasty, who paid tribute in Beijing three times every year (一年三使). A typical Korean tribute mission would comprise 30 people staying in Beijing for 40 days. Other important tributaries included Ryukyu (a small archipelago now part of Japan), Vietnam, Thailand (or Siam, if you prefer), Malacca (a sultanate on the Malay peninsula and Sumatra), and various Mongol and Manchu groups on the northern border. In the height of the Ming tributary system, foreigners from Africa to Japan paid tribute to the court. This of course does not include various foreign peoples the Ming fought, such as aboriginal peoples in areas colonized by the Chinese to (of course) the Mongols.
So the Ming were very acquaintanced with foreigners, and the arrival of the Portuguese would not have caused great shock.
Let's say you're a provincial official in Guangdong, where the Portuguese are arriving (most officials in Beijing aren't really thinking about the Portuguese). At first you're not too upset about these Portuguese who are coming to Guangzhou with their big ships. As KimCongSwu notes, the Ming are used to foreigners -- and not just from all those tribute missions. There's a lot of semi-private and unofficial trade in Guangdong. But after a promising start, the Portuguese start to cause some serious trouble, so you have to drive them away by force of arms. The first year's battle (1521) doesn't go terribly well, because your fleet is a bit ad hoc and the Portuguese have some pretty kickass guns. But the next year (1522) you completely dominate, because you've got a good fleet with better guns. The Portuguese are now scared of you. They go northward to Fujian and Zhejiang Provinces, where other officials have to deal with them. You are rewarded for your work and receive promotions. You champion the use of Portuguese-style guns on the Great Wall. You've done pretty well for yourself and have become rich and famous, but be careful in the factional strife among court officials. It's seriously like a vituperous Reddit comment section all up in there. You might lose your imperial favor.