Phthalocyanine (Pc) molecules are well-known flexible structural units for 1D nanotubes and 2D nanosheets. First-principles calculations combined with grand canonical Monte Carlo simulations are used to obtain the geometries, electronic structures, optical properties, and hydrogen-storage capacities of nanocages consisting of six Pc molecules with six Mg or Ca atoms. The primitive Pc cage has Th symmetry with twofold degeneracy in the highest occupied molecular orbital (HOMO), and threefold degeneracy in the lowest unoccupied molecular orbital (LUMO); the corresponding HOMO–LUMO gap is found to be 0.97 eV. The MgPc and CaPc cages have Oh symmetry with a HOMO–LUMO gap of 1.24 and 1.13 eV, respectively. Optical absorption spectra suggest that the Pc-based cages can absorb infrared light, which is different from the visible-light absorption in Pc molecules. We further show that the excess uptake of hydrogen on MgPc and CaPc cages at 298 K and 100 bar (1 bar=0.1 MPa) is about 3.49 and 4.74 wt %, respectively. The present study provides new insight into Pc-based nanostructures with potential applications.