What do you do when the boss has a bad idea, but you can't tell him it's a bad idea?

Welcome to the world of Defense Secretary Jim Mattis, the man whose job it is to turn President Trump's impulsive orders into something the military is happy to salute.

The latest edict: Trump’s order to send active-duty troops to the Mexico border to repel the coming “onslaught” of Central American refugees seeking asylum in the United States.

Mattis is carrying out the order in a way that will allow the president to trumpet the deployment, while keeping the troops out of the literal and political line of fire.

The high-profile dispatch of a few hundred troops is largely symbolic due to longstanding legal restrictions against active-duty troops engaging in domestic police work. Instead these are mainly support personnel, not infantry, whose jobs will involve providing security for border guards, erect temporary barricades and fencing, ferry guards around on helicopters, give them body armor, and build temporary housing for them.

These are all jobs that can, and some argue should, be done by law enforcement or private contractors.

“I think that [you’ve] got to be very careful how you use the military,” said retired Gen. Stanley McChrystal on CNN. “It's not a police force and it should never be a police force.”

But what Mattis is doing both fulfills a humanitarian mission and a political goal, says Harry Kazianis, director of defense studies at the the Center for the National Interest.

“These troops can help with basic fencing, technical support and even helping with wall materials in places where migrants could cross. They can also help with medical support and even provide tents,” Kazianis says.

“Perhaps most importantly, these troops will be plastered all over the media. It shows the administration is doing something about this issue. And by sending in the military, it shows it is a top national priority,” he said. “This president gets that optics matter to the American people and his base. Sending troops means he is taking action — the biggest action he can.”

It’s a special kind of alchemy that Mattis is able to perform, taking ideas that initially go over like a lead balloon and gilding them just enough to given them a veneer of acceptability, while at the same time not undercutting the president’s message.

He’s done it time and time again.

When Trump shocked the Pentagon with his plan to scrap “expensive war games” between the U.S. and South Korea, Mattis figured out that as long as they made a show of canceling major exercises with dangerous sounding names, regular training could go on unaffected safely under the radar of Trump and the North Koreans.

When Trump — impressed by the over-the-top Bastille Day parade he witnessed in Paris — ordered his own military extravaganza down Pennsylvania Avenue, Mattis saluted smartly and then gradually pared back while finding a way to link it to the 100th anniversary of the end of World War I.

The idea was wildly unpopular in the Pentagon, but it gradually sank under the weight of the cost of local security that would have been billed to the federal government by the District of Columbia.

A similar fate befell the Trump administration’s plans to house immigrant children and families on U.S. military bases.

After a flurry of activity including site surveys and environmental assessments, Health and Human Services officials were convinced “these are not the facilities” you’re looking for.

It’s notable that no Pentagon officials would comment on the record for this report, out of fear that another account of how Mattis is managing could infuriate Trump and end Mattis' tenure as Defense secretary.

Already there are rumors that Trump is considering replacing Mattis after the midterm elections with someone more in line with his thinking.

Both Mattis and Trump have denied those rumors, yet another sign of Mattis' unique ability stay on the president’s good side, while saving him from his most capricious ideas.

Call it “The Mattis Touch.”