Secretary of State Cyrus Vance will visit both Turkey and Greece later this week, but the two nations cautioned the United States yesterday against attempting to mediate their long-smouldering dispute over Cyprus.

State Department spokesman John Trattner, in announcing that Vance would arrive in Ankara Friday and then fly on to Athens Saturday, indicated that the Carter administration felt the two countries might finally be ready to negotiate a Cyprus settlement.

Greece and Turkey have been at loggerheads over Cyprus since 1974, when a coup backed by the military government then in power in Athens toppled the government of Cypriot President Archbishop Makarios.

The Turkish army subsequently invaded Cyprus and seized control of 40 per cent of the island. Greece has since been demanding that Turkey return much of this area to Greek Cypriots, since Turkish Cypriots make up only 18 per cent of the island's population.

Trattner said the United States had been "very encouraged" by signs that Turkish Prime Minister Bulent Ecevit, whose new government was confirmed by Turkey's Parliament yesterday, "intends to work for a quick solution" to the Cyprus dispute.

The Carter administration also considers it encouraging that Greek Prime Minister Constantine Karamanlis has noted with satisfaction certain elements of Ecevit's recent statements, Trattner said.

But in Ankara, Ecevit said yesterday that he had invited Vance to stop off on his way home from Middle East peace negotiations to discuss Turkish-American problems - not Cyprus.

Ecevit's foreign minister, Gunduz Okcum, warned the United States even more bluntly against becoming "directly involved" in Turkish disputes with Greece. The two countries, Okcum declared, are "mature enough to solve their own problems."

The Vance visit was being viewed with equal skepticism in Athens, where only last week the Karamanlis government declared that Greece and Turkey should be left to settle their problems alone.

The prospect of U.S. intervention on the Cyprus question drew immediate fire from the powerful Greek political opposition - which insists that the dispute must be solved through an international conference.

"Why has the prime minister agreed to see Vance?" opposition leader Andreas Papandreou asked last night. "The Vance visit confirms that the government is being pressured to make concessions."

U.S. optimism that progress might now be possible on the Cyprus issue appears to be based largely on the return to power in Ankara of Prime Minister Ecevit, who led the Turkish government that ordered the 1974 invasion.

Ecevit indicated his willingness to tackle the Cyprus problem in talks last week with U.N. Secretary General Kurt Waldheim. The new prime minister said yesterday that he would announce his proposals for assuming the deadlocked Cyprus peace talks after consultations with Turkish-Cypriot leader Rauf Denktash, who arrives in Ankara today.

Karamanlis, for his part, has reacted to Ecevit's statements with cuation. "Neither optimism nor pessimism is justified before these proposals are known," the Greek prime minister declared.

Many Greek government officials are highly skeptical of the view held by Western diplomats that Ecevit - as the man who ordered the Turkish Army into Turkey - is the most logical candidate to bring the troops home.

Greek officials suspec that Ecevit's recent overtures may be no more than window dressing to induce the U.S. Congress to lift the crippling arms embargo it imposed against Turkey following the Cyprus invasion.

The arms embargo, and the subsequent Turkish decision to retaliate by closing U.S. intelligence gathering installations that monitored miliatry movements in the Soviet Union, have poisoned Turkish-American relations since that time.

In March 1976, the Ford administration reached an agreement with the Ankara government under which Turkey would receive $1 billion in military aid over four years in return for restored U.S. access to its monitoring stations.

The Carter administration has endorsed the agreement in principle, but it decided to await progress on Cyprus before attempting to win congressional approval for a resumption.

Ecevit is expected to press Vance during their Ankara talks to make an effort to get the military aid package through Congress, arguing that without it, Turkey will not be able to NATO.

The question of U.S. bases is also expected to arise during Vance's talks in Athens with Karamanlis. A new agreement on American bases in Greece was reached last fall under which the United States would provide $700 million in military aid to Greece over a four-year period.

The Greek government, however, has not signed the agreement. U.S. officials think Karamanlis government, which was concerned over leftist efforts to exploit the base issue in national elections late last year, may now be ready to sign the pact. Trattner said, however that he did not expect the agreement would be signed during Vance's visit this weekend.