WASHINGTON (AP) _ The State Department, concerned that spies aided by U.S. Marines blew the security lid at the Moscow embassy, said Thursday it is taking ''all the necessary steps'' to safeguard Secretary of State George P. Shultz's secret communications when he goes to the Soviet Union April 13.

The department also announced it is bringing home its security officer in Moscow - the civilian in charge of the Marine detachment - to answer questions about how the affair developed.

State Department spokesman Charles E. Redman, acknowledging concern about Shultz's trip, said ''we are taking all the necessary steps to insure that we have secure communications in Moscow by the time of the secretary's visit.''

''We are working with technical experts from other U.S. government agencies to insure that the secretary has the kind of security that he needs for his upcoming trip,'' Redman said. ''The secretary will be able to do what he needs to do.''

He repeated an announcement that the investigators are assuming, for purposes of their probe, a ''worst case'' scenario.

Meanwhile, it was reported today that President Reagan was warned two years ago by his Foreign Intelligence Advisory Board, a group of private citizens, that the U.S. embassy in Moscow was vulnerable to Soviet espionage.

The New York Times, quoting government officials who were not named, said the report helped persuade Reagan to decrease the number of Soviet employees at the embassy, but resulted in few changes in security procedures.

White House spokesman Ben Jarrett and State Department spokeswoman Deborah Cavin had no comment on the story. Texas billionaire H. Ross Perot, a member who resigned from the panel after the report went to Reagan, could not be reached for comment, his spokesman said.

Shultz's trip, planned before allegations that activities by two Marine guards compromised security at the embassy, is part of the long-standing U.S.-Soviet effort to narrow differences on arms control and perhaps plan for President Reagan's third summit with Soviet leader Mikhail Gorbachev.

Redman declined to say whether Shultz would raise the spying affair - allegations that Marine guards Sgt. Clayton Lonetree and Cpl. Arnold Bracy were enticed by women into providing embassy secrets to the Soviets.

There has been special concern about the security of communications in the embassy because of allegations that Soviet agents were allowed to roam top secret workplaces where communications equipment is kept.

Both men are in custody at the Marine base in Quantico, Va. and a third member of the 28-Marine guard detachment, Staff Sgt. Robert S. Stufflebeam, is being detained on suspicion of having improperly socialized with a Soviet woman.

Under long-standing procedures, the Marines at embassies are responsible for making sweeps through missions at night to make sure classified material is properly put away. In Moscow, as at other sensitive posts, they also are required to report social contacts with local citizens.

Marine guard detatchments at embassies are headed by enlisted men and report to State Department regional security officers, who bear the ultimate responsibility for protecting the missions.

In recent days, with publicity about the Moscow affair mushrooming and reports from the Soviet capital of loose control over the Marine detachment, military officials have complained privately that young Marines have been publicly identified as the targets of the intelligence review and that the State Department's overall responsibility has received less public attention.

The department announced on Monday that all 28 Marines in the detachment were being rotated to the United States and that they would be replaced by other marine guards.

On Thursday, Redman announced that the current regional security officer assigned to the embassy, Frederick Mecke, is temporarily returning to Washington to consult with various security officials.

''He is a key person in the chain of command and as a consequence is in a position to know how things developed there,'' Redman said.

''We're going to be talking to everyone at the embassy,'' Redman said. ''Certainly the RSO falls into that category.'' A new officer will be sent to take his place, the spokesman said.

Mecke joined the State Department in 1976 and has served as a security officer in Washington, San Salvador, El Salvador; Nairobi, Kenya; and Managua, Nicaragua.

The department said he was assigned to Moscow in August 1985. Lonetree served in Moscow from September 1984 to March 1986.