Microscopic characterization of metal-carbon-hydrogen composites (metal = Li, Mg)