The CIA was challenged in federal court yesterday over its censorship of a forthcoming magazine article accusing the agency of fabricating documents to back up allegations of Soviet and Cuban arms shipments to guerrillas in El Salvador.

The lawsuit was the first such case brought against the CIA since its prepublication review powers over present and former employes were upheld last year by the Supreme Court.

The suit was filed in U.S. District Court here by Ralph McGehee, a former CIA officer and counterinsurgency expert. He charged in the article that the agency was manipulating U.S. public opinion on El Salvador as it had done in earlier "disinformation" campaigns with which he was familiar.

The CIA did not censor any of McGehee's allegations about current events in El Salvador, but did delete an array of details about past CIA operations, especially in Indonesia in the mid-1960s.

There, McGehee charged in a sanitized version of the article attached to the lawsuit, "media fabrications" about the murders of some leading Indonesian generals helped set the stage for the slaughter of more than 500,000 people.

McGehee's lawyer, Mark Lynch, maintained that the portions censored were "not properly classified" and that their deletion constituted an "unreasonable" degree of prior censorship in violation of the First Amendment.

The censored article will appear in the next issue of The Nation magazine, but Lynch said The Nation, also a plaintiff in the case, would publish the unexpurgated version if the lawsuit is successful.

CIA spokesman Herbert Hetu declined to comment on any of McGehee's charges.

In the article, McGehee, who served with the CIA for 25 years before retiring in 1977, said that "what the United States is now attempting in El Salvador is merely a reflection of what the United States has done in many countries" of the Third World -- supporting a military or autocratic regime while labeling the opposition "communist or terrorist."

"When events do not sustain those claims," McGehee charged, "the CIA manufactures the appropriate 'proof.'" He maintained that reports in JANUARY ABOUT GUERRILLA INVASION EFFORTS WERE A "PROBABLE CIA deception operation" to justify U.S. military aid.

McGehee also charged that an 18-pound cache of documents provided to a State Department official in mid-January by the Salvadoran national police could have been "none other than the product of yet another CIA forgery operation."

"Miraculously, the documents provided ample proof that the Cubans had supplied weapons to Salvadoran insurgents," McGehee wrote. Such support to Latin American movements, "while it may occur, has usually been virtually impossible to document in the past," he wrote.

McGehee likened the episodes to what he called similar "disinformation" campaigns in Iran in 1954, in Chile in the early 1970s and elsewhere, but he rested his case primarily on events in Indonesia in 1965.

Following the overthrow of the Sukarno government there, he charged, mass killing began in central Java after public emotions were stirred by repeated publishing of photos of the murdered generals, "with accompanying texts falsely claiming that the generals had been castrated and their eyes gouged out by communist women."

McGehee claimed that the CIA later published a false account of what had happened "to conceal its role in the massacre" that ensued.