They are all here: presidents, prime ministers and potentates from scores of nations, the largest gathering ever of world leaders.

They are here to mark the day, 40 years ago, when the guns of World War II had only recently been silenced and when a new charter creating the United Nations was put into effect. That charter, signed initially in San Francisco in June 1945 by a far smaller group of leaders than is here today, was based on the postwar hope that reason rather than guns might ultimately prevail.

But while another global conflict has been averted, there is widespread disenchantment with the institution of the United Nations, whose membership has more than tripled from the original 51 to 159.

This institution is facing a crisis that sometimes comes to people at age 40, in the view of many critics and some backers, because the international community still has not evolved a coherent system for fulfilling its primary purpose -- the resolution of disputes between nations.

Its critics attack it on the grounds that it produces more rhetoric than action, a place for nations to let off steam -- the "Turkish bath" syndrome, said former U.S. ambassador Jeane Kirkpatrick. The one-nation, one-vote system in the General Assembly, these critics say, allows the Third World countries, that make up more than two-thirds of the members, to dominate with antiwestern diplomacy.

American critics have said that assembly debates and resolutions exacerbate disputes rather than help resolve them when the side with the majority pushes through resolutions that make problem-solving by other U.N. organs more difficult.

Supporters counter that the United Nations was never meant to be a panacea. "It's supposed to be a machinery which governments can use to avoid the disasters they've already experienced twice in this century," said Brian Urquhart, the veteran undersecretary general for special political affairs. " . . . We should get away from this idea that it's either/or. You have a world of sovereign states. Sovereign states, if they possibly can, should settle their own problems in a peaceful way. If they can't do that they have the option of coming to the United Nations. Sometimes the United Nations can be extremely helpful and sometimes it can't."

Urquhart and others say the organization has been able to contain disputes and halt fighting and can still do so in the future. The disputes that have erupted into bloodshed have left an indelible record, they say. It is harder to ascertain or remember the times when war has been averted.

"The U.N. has acted to prevent many more armed conflicts than the number, which is put at about 300, that have taken place since 1945," said Austria's foreign minister, Leopold Gratz.

While there may be wide disagreement over the effectiveness of the highly visible political bodies, the Security Council and the General Assembly, there is little argument over U.N. accomplishments in other fields: virtual elimination of smallpox by its World Health Organization, codification of human rights and other aspects of international law, coordination of aid to feed Bangladesh in the 1970s and treat the African famine in the 1980s. From Weather to Control of Weapons

Over the years, the United Nations and its family of about 40 autonomous agencies and programs have evolved to deal with tasks ranging from the collection of weather statistics (by the World Meteorological Organization) to safeguarding against nuclear weapons proliferation (by the International Atomic Energy Agency.)

"The peoples of the Third World see a different U.N. than you do in the West," said one African ex-ambassador, now elevated, like many who pass through the U.N. system, to the post of foreign minister. "For us, the U.N. is the expert who helps our farmers build an irrigation system, or the nurse who inoculates our children. The U.N. means hope. It is a success story. You don't need these services. For you, the U.N. is the frustration of a Security Council veto or the irritation of a General Assembly resolution."

But the staunchest supporters recognize that if the institution's political arms are further weakened, the institution will lose capacity to function in other areas.

The Security Council, which was given broad powers for collective action to keep the peace, including the ultimate recourse to the use of force, never developed its original role as a deterrent. The assumption that the big powers, the United States, the Soviet Union, China, Britain and France, would share a common interest in dispute settlement faded quickly with the split among the World War II allies.

Over the years, this polarization diminished the ability of the council -- as well as the General Assembly, the World Court and the secretary general -- to resolve disputes, observers say.

It was "as if one of the great pillars fell in right at the beginning, which was the unanimity of the great powers, and we have been improvising around that ever since," said Urquhart.

U.N. accomplishments have been enhanced by two major innovations not envisaged in its Charter -- peace-keeping operations and the evolution of the office of secretary general into a personal channel for settlement of disputes.

Peace-keeping began with the use of U.N. observers in the Middle East in 1948 in the first Arab-Israeli war. The presence of U.N. observers or peace forces between rival armies also helped control or contain violence in Cyprus, the Congo and on the India-Pakistan frontier.

The secretary general's role began expanding as early as 1946, when the first, Trygve Lie, played a quiet role in the peaceful evacuation of Soviet troops from Azerbaijan Province in northern Iran. Dag Hammarskjold's mediating efforts, starting with the 1956-57 Suez crisis, have been the most conspicuous. But his successor, U Thant, played a vital role in defusing the 1962 Cuban missile crisis. Kurt Waldheim tried unsuccessfully to negotiate the release of the Americans held in Iran.

Javier Perez de Cuellar has taken this function a step farther, contending that under international "common law" his office is an appropriate channel to address all disputes that have stymied the Security Council.

U.N. governing bodies have raised no objection to the establishment by Perez de Cuellar of an "early warning system" in his own office to alert the world to potential disputes. He has exceeded Security Council or General Assembly mandates in seeking to mediate conflicts in the Falklands, Cambodia, Cyprus, the Middle East, Afghanistan and the Persian Gulf.

One reason for the resurgence of the secretary general's role has been the Security Council's decline. In the early years, the United Nations dealt with virtually all conflicts, including such East-West crises as those in Korea and Hungary -- although it could not resolve them. The gap between global reality and U.N. practice became pronounced with Vietnam, an issue that the United Nations did not treat, at U.S. insistence, despite the persistent attempts by Thant to intervene as peacemaker.

The gap widened when negotiations on southern Africa and the Middle East moved out of the U.N. orbit.

The secretary general's efforts and all other intergovernmental mechanisms for settlement of disputes are hampered by a common problem: they cannot intervene unasked in domestic situations until after things get out of hand, observers say.

Many international disputes -- Vietnam, the Indian invasion of Pakistan that created Bangladesh, Cambodia, Afghanistan, Grenada, the ongoing insurgencies in Angola, Nicaragua and El Salvador -- have had their origin in domestic crises.

"No organization run by governments can permit itself to intervene in a state's internal affairs," said one U.N. official. "That is admittedly a major gap in the system."

In recent years, the Security Council has failed to act on Perez de Cuellar's suggestion that it improve its capacity to deal with disputes by bringing into its closed consultations those parties that are not council members. It has not followed up on resolutions adopted on Namibia, Lebanon and the Persian Gulf war.

One reason is that council members now tend to search for common language to avoid vetoes, resulting in vague resolutions that have preserved unanimity at the expense of tangible action, observers say.

In addition, the alienation between Washington and Moscow has limited U.N. effectiveness since the beginning. One of Perez de Cuellar's aides noted that even Hammarsjkold operated efficiently only when the major powers wanted him to act, as during the Suez crisis, or when one or both were not involved directly, as in the start of the Congo operation. Today, he said, there are few issues in which the superpowers have no stake.

The Soviet Union, which never exercised control of the Security Council, has traditionally been hesitant to use U.N. mechanisms for dispute settlement, preferring bilateral arrangements with Washington. Under the Reagan administration, Washington has also adopted a policy of avoiding multilateral forums in which the United States cannot exercise control.

The last time the council acted decisively to avert a crisis was in December 1973, when the Nonaligned Movement members of the council proposed the installation of a new peace force in the Sinai, and enabled the United States and the Soviet Union to back away from a confrontation there that might have escalated to global proportions.

"Given the current superpower relationship," said one U.N. official, "the best that can be hoped is that the council's mechanisms won't rust, and that it can hunker down until policies change; that the present impasse is merely cyclical." The U.N. as Seen From Washington

In recent years, the United States has been more successful in the General Assembly. It has avoided debates on Puerto Rico and Antarctica, deleted anti-American rhetoric from resolutions, averted the expulsion of Israel and prevented an invitation to Palestinian leader Yasser Arafat to attend this week's birthday festivities on a par with President Reagan.

Nevertheless, Washington has moved in recent months to limit the movements of Secretariat members in the United States, cut back on the assembly's prerogative to appropriate monies that the United States is obliged to pay, withdrawn from compulsory World Court jurisdiction on political issues and withheld voluntary funding from U.N. agencies.

More ominous, in the opinion of U.N. officials, is the administration's perception of the U.N. role. In a speech in San Francisco in June celebrating the signing of the U.N. Charter 40 years before, Secretary of State George P. Shultz served notice that from his viewpoint, the days of U.N. activism in dispute settlement have passed.

"We would all prefer that the U.N. could always play the role of peace-keeper," Shultz said. "But we have had to accept the limitations of the real world: the international consensus which the founders hoped for has broken down." As a result, he said, "nations have had to resort to their own agreed methods of keeping the peace."

Urquhart replied that the organization obviously would prefer "if the countries directly concerned can solve their own problems themselves." The problem is, he said, that they very often are unable to do so.

"We're trying to go forward from the period of unbridled national action, which has led us into two major disasters this century, and has now been capped with the possibility of putting an end to the whole thing with nuclear weapons," said Urquhart.

"What we're missing is the political roof over this whole thing, and that's what I hope everybody will think more about . . . . At the moment, what we have in times of emergency is an emergency roof, which we put up, and then it gets destroyed very quickly when the emergency is over. The most important thing is to try to get people to recognize that a permanent structure on the political, the peace-and-security issue, is something, in the long run, in all their interests."