Osteoporosis is the most common bone metabolic disease that affects the health of middle-aged and elderly people, which is hallmarked by imbalanced bone remodeling and a deteriorating immune microenvironment. Magnesium and calcium are pivotal matrix components that participate in the bone formation process, especially in the immune microenvironment regulation and bone remodeling stages. Nevertheless, how to potently deliver magnesium and calcium to bone tissue remains a challenge. Here, we have constructed a multifunctional nanoplatform composed of calcium-based upconversion nanoparticles and magnesium organic frameworks (CM-NH2-PAA-Ald, denoted as CMPA), which features bone-targeting and pH-responsive properties, effectively regulating the inflammatory microenvironment and promoting the coordination of osteogenic functions for treating osteoporosis. The nanoplatform can efficaciously target bone tissue and gradually degrade in response to the acidic microenvironment of osteoporosis to release magnesium and calcium ions. This study validates that CMPA possessing favorable biocompatibility can suppress inflammation and facilitate osteogenesis to treat osteoporosis. Importantly, high-throughput sequencing results demonstrate that the nanoplatform exerts a good inflammatory regulation effect through inhibition of the nuclear factor kappa-B signaling pathway, thereby normalizing the osteoporotic microenvironment. This collaborative therapeutic strategy that focuses on improving bone microenvironment and promoting osteogenesis provides new insight for the treatment of metabolic diseases such as osteoporosis.