Mayor Marion Barry, looking beyond the Nov. 2 general election in which he is heavily favored to win another four-year term, has been taking steps to impose new discipline on the D.C. Democratic Party.

Barry has indicated that he is unhappy with the performance of D.C. Democratic State Committee chairman Theodis R. (Ted) Gay because Gay resisted giving Barry the party's official endorsement before last month's primary elections, and that he may try to oust Gay in favor of a more supportive chairman.

Gay said in a recent interview that Ivanhoe Donaldson, Barry's chief political adviser and campaign manager, told him Barry felt Gay should have had the party back the incumbent Democratic mayor.

In an interview, Gay said Donaldson stopped short of asking him to resign, but sources indicated Barry may back another candidate for the chair next June if Gay remains in office.

The leading candidate to replace Gay apparently is former Democratic party chairman Robert B. Washington Jr., an adviser to Barry's campaign. Washington brought together two-thirds of the state committee's members in August and orchestrated their endorsement of Barry. But Gay, who did not attend the endorsement party held at Face's restaurant on Georgia Avenue, prevented the endorsement from becoming an offical action of the party.

"Ivanhoe very candidly said to me that he and the mayor thought I should have come out as head of the party and endorsed the mayor," said Gay. Gay also described a meeting two weeks ago at the Hotel Washington with Donaldson and another Barry political aide, Anita Bonds, at which the issue of his refusal to position the party behind Barry was discussed. "I responded that I am not unhappy with my position that as chairman of the party I represented all the Democrats," Gay said.

Gay said the party has never endorsed any candidate--including incumbents -- before a primary, but he said he was not surprised at Donaldson's anger for his failure to break with party tradition to benefit Barry.

"I can see a campaign manager trying to get every endorsement for his candidate," said Gay, who did personally endorse Barry. "I took what he said to be his strong opinion. But I am not resigning."

Neither Donaldson nor Barry could be reached for comment.

Washington, who declined to run for reelection as head of the party in 1981, said he has discussed the post with Donaldson, but said he would be reluctant to accept it.

"I have had a number of people approach me about taking the job in the last few days," said Washington, who holds several high posts in the Democratic National Committee. "I support Marion. I'm close enough to have my calls returned, but I have enough independence to head the party."

According to sources, Washington and Barry's supporters are backing a proposal to create a second vice-chairman's position in the state organization that could be given to Gay.

"The mayor should play an important role in the party," said at-large Democratic State Committee member and Barry supporter Paula Nickens. "We as members of the Democratic Party should listen to him and follow his lead. There's nothing wrong with that. He is the mayor."

Barry supported Gay for party chairman in 1981. But at the time, committee members said that decision had less to do with Gay himself than with a feud Barry was then having with Washington Teachers Union President William H. Simons, who ran against Gay. Barry and Simons had fallen out over an earlier bid by Simons to become party chairman, and Barry was seeking a neutral candidate to replace the retiring Washington.

One of Barry's problems with Gay's performance, according to sources, is that Gay has failed to become an influential personality in city politics, much less national politics. With the 1984 presidential election approching, the sources said, Barry wants to be in position to become influential nationally. Barry has never been a major figure in national party politics, unlike some other big-city mayors.

"Ted is vulnerable and Marion wants him out because he thinks he would rule the party through Bob Washington ," said Barbara Clark, vice chairwoman of the state committee. "I think Bob wants to come back for the presidential elections."

Gay, who runs an art framing shop, does not fit the mold of past heads of the party, who have included Washington, a lawyer with an international clientele; William Lucy, the secretary-treasurer of the American Federation of State, County and Municipal Employees; and Joseph Rauh, a well-known lawyer and civil libertarian.

Meanwhile, as the Nov. 2 election approaches, Barry is doing practically no campaigning. His major opponent, Republican E. Brooke Lee, has twice come to Western Plaza across from the District Building with a bullhorn to yell up at Barry's window and ask for a debate.

Last Thursday, Lee brought two mules to the plaza, one of which was named Marion, and shouted questions at the animals in an attempt to dramatize Barry's refusal to debate.

Barry later said he would debate if all four candidates on the ballot -- including independent Dennis Sobin and Socialist Workers Party candidate Glenn B. White--are included. But no plans are being made for a debate and no television or radio station has shown any interest. More than three-fourths of the city's voters are registered as Democrats and the winner of the Democratic mayoral primary is generally expected to be the winner of the general election.