James McDonald scattered four hits over seven innings and struck out 10 as the Pittsburgh Pirates edged the San Francisco Giants, 3-1.