Three weeks after President Reagan visited Mexico to demonstrate his good neighborliness, relations between the two countries are already being tested by the conservative swing of Washington's policy toward Central America.

This week, Mexican officials sharply criticized the U.S. decision -- made under the Carter administration but believed to be supported by Reagan -- to resume "lethal" military aid to help El Salvador's embattled government fight off a threat from the left.

In an obvious reference to the aid decision, Mexican Foreign Minister Jorge Castaneda this week said that the Salvadorans must "solve their own problems." If not, he said, The bloodshed will be even greater and the conflict will inevitably become an international one."

Gustavo Carvajal, president of Mexico's ruling Institutional Revolutionary Party, said pointedly that the party will support a people "that fights for its freedom." Last week, while U.S. officials accused Nicaragua of aiding Salvadoran guerrillas with arms and men. Carvajal flew to Managua and told officials there that "Nicaragua is not alone."

Thursday, one of the largest anti-American demonstrations here in recent memory was organized by 60 trade union and leftist groups to protest "U.s. intervention" in El Salvador. About 25,000 people marched, carrying banners saying "Yankees, hands off Salvador." They collected money for the guerrila offensive and burned U.S. flags.

Privately, Mexican officials say they are deeply worried by the swing in U.S. policy that they say became apparent when the Carter administration in its final days decided to resume military aid to El Salvador. Since then, Washington has considered suspending economic aid to Nicaragua's revolutionary government, pending investigation of the use of the funds.

Mexico aids and sympathizes with both the Nicaraguan government and the leftist trying to oust the U.S.-backed Salvadoran government.

On no other issue are the United States and Mexico so far apart. In contrast to the support Latin America's other oil power, Venezuela, gives the Salvadoran rulers, there is a belief in the government here that a hardening of U.S. policy will further radicalize the Central American struggle.

Even before the United States announced its intention to send weapons to the Salvadoran military, Castaneda had suggested that Washington consult with Mexico whenever the United States decided "on major issues affecting the area." Well-placed sources here said Mexico has sent "messages of concern" to Washington.

This week's public protest of the U.S. decision is viewed as a portent of bitterness that could grow if the United States increases its role in El Salvador and actively backs the military junta in Guatemala, where rightist repression has also polarized the populace.

Even if the Mexican government hopes to have good relations with the Reagan administration, it will have to heed nationalists and the left here, who not only have the loudest voice in this country but whose position also matches the image Mexico likes to project abroad.

Much of Mexico's press is vigorously prorevolution and anti-American.

But the government itself is clearly willing to play a role that goes beyond appeasing the liberals and the left. Recently, for example, when El Salvador announced plans to take its case to the Organization of American States to denounce Nicaraguan and Cuban intervention, in an effort to justify help from other OAS members under the Rio de Janeiro treaty, key Foreign Ministry officials here reacted warily.

"Going before the OAS is a double-edged knife," said one top official. He warned that Mexico in that case would have to deal with "the barbarous torture and killings of civilians by the Salvadoran military." Moreover, the offical said, an OAS debate would "blow the image the U.S. has so carefully wrought of the junta in El Salvador."

Washington has maintained that El Salvador's government is moderate and caught between extremist violence of the left and the right, but one high Mexican official said that while the Salvadoran military "have killed thousands of leftists and innocent people, they have rarely or never jailed or killed an extremist of the right."

Mexico's official help to the Salvadoran opposition nonetheless has been discreet. Mexico is clearly waiting to see if the civilians and guerrilla groups improve their chance to take power. So far neither the government nor the guerrillas have demonstrated that they can control the situation.

But in the meantime, Mexico has helped finance strictly political activities of the Democratic Revolutionary Front, the umbrella organization that embraces all Salvadoran opposition civilian and guerrilla groups.

Mexico City recently became foreign headquarters for the front, whose members often hold news conferences. The many factions of the front have coordinating offices here, and Mexican solidarity groups drum up support, selling posters and collecting money.

Friday a group of two dozen Mexican leftists peacefully occupied the embassy of El Salvador here for about five hours, demanding that Mexico break relations. Mexico, which broke diplomatic relations with the government of Nicaragua's Anastasio Somoza several months before its overthrow, has said that at this time a break would serve little purpose and close the door to people asking for political asylum in its embassy in San Salvador.

Significantly, Mexico still honors the agreement under which it and Venezuela give credit to finance oil purchases. El Salvador is one of nine small nations to get such advantages in this area. The Mexican president has argued that crossing El Salvador off the list would be the kind of economic sanction that Mexico protests when applied by other countries.