Improving the efficiency of thermoelectric generators (TEGs) used to harness residual heat from automobile exhausts is crucial for their widespread adoption. To enhance fluid heat transfer, the Kelvin tetrahedron model is employed for metal foam, and a multiphysical field model of the thermoelectric generator based on metal foam is established. The effects of inserting metal foam with uniform and gradient pore densities into the heat exchanger on the performance of the TEG are investigated. Experimental verification is conducted by constructing a test bench with dimensions identical to those of the model The findings suggest that inserting foam metal significantly enhances the output performance of the TEG, resulting in increases in both output power and efficiency as pore density rises. At Ta = 573 K and ma = 30 g/s, the output power of the TEG with inserted 20 PPI foam metal is enhanced by 140.46 %, while the efficiency experiences a remarkable increase of 197.50 % compared to a smooth pipe. Compared to the performance metrics of uniform foam metal, the positive gradient foam metal exhibits a maximum power increase of 7.89 % and a maximum efficiency increase of 34.46 %, along with an average pressure drop reduction of 27.29 %.