The Senate has urged President Reagan to use an obscure section of the tax code to deny tax breaks to U.S. companies that buy two kinds of machine tools made in Japan.

In a unanimous "sense of the Senate" vote late Tuesday night, senators said that the government of Japan fosters illegal cartels among manufacturers of these machine tools, and that the cartels -- which also receive special favors from the Japanese government -- enable Japanese manufacturers to undersell U.S. producers of the machines.

Machine tools are used in industry to cut metal and make parts.

The Senate resolution is a response to a filing before the U.S. Trade Representative by Houdaille Industries last May. Houdaille, a Florida manufacturer, asked Reagan to invoke a provision of the 1971 Tax Reform Act that empowers him to suspend eligibility for the investment tax credit -- in most circumstances 10 percent -- on purchases from overseas if the president determines that a foreign government has restricted U.S. commerce unjustifiably by fostering "international cartels."

Government sources said an interagency task force assigned to study the Houdaille petition nearly has completed its work and may have a recommendation within a few weeks. Reagan administration officials fear that growing protectionist sentiment in the United States and abroad -- sparked in large part by the severe worldwide recession -- could trigger a trade war among industrialized countries.

In its May petition, Houdaille Industries said that, if the tax credit were denied to U.S. companies that buy these machine tools -- called numerically controlled machining centers and numerically controlled punching machines -- Japanese manufacturers would have to cut prices by 15.2 percent to remain competitive.

According to the Houdaille petition, Japanese machining centers accounted for about 4 percent of all machining centers sold in the United States in 1976. That market share grew to about 50 percent during the first three quarters of 1981. Richard Copaken, who works for Houdaille's law firm, Covington & Burling, said yesterday that the Japanese share grew to 60 percent during the first half of 1982.

For the punching centers, Japan's share of the U.S. market grew from 4 percent in 1976 to 38 percent in 1981 and to 46 percent during the first half of 1982.

Copaken said the U.S. machine tool industry is on a collision course with bankruptcy because of the recession and the sharp increase in imports from Japan.

Houdaille, which has sales of about $500 million, spent nearly $750,000 researching the alleged cartel arrangement in Japan, Copaken said.

The petition charged that Japan first fostered the growth of large machine tool makers in the 1950s, weeding out small, inefficient producers and using special laws to exempt the industry from the nation's antitrust laws.

Houdaille also charged that the machine tool industry received special favors from the government of Japan, including low-cost loans for research and development and the covert investment of portions of the proceeds realized from betting on motorcycle and bicycle races.

Copaken said that Japan's Ministry of International Trade and Industry at first said that those wagering proceeds averaged about $300,000 to $400,000 a year, but admitted in filings with the Trade Representative's Office that, in one year at least, the amount totaled more than $100 million.