As Secretary of Defense, Robert McNamara was second only to President Johnson in the US military hierarchy. Because of this, he had a great deal of responsibility in creating the rules of engagement for US forces in Vietnam. The rules of engagement are often referred to as the "Johnson-McNamara" rules of engagement.
During President Johnson's time in office, he and McNamara worked together to create the rules of engagement. The two of them were, of course, very concerned with the overall impact that US military operations would have on the US's standing in the world and on its relationships with China and the Soviet Union. They had to be thinking on that level rather than just thinking about what would be good for the individual Americans who had to fight in the war. For this reason, McNamara helped to craft restrictive rules of engagement that (one can argue) ended up making the US less likely to win the war.