Owing to challenges in the study of complex rhizosphere and endophytic microbial communities, the composition and function of such microbial communities in steppe ecosystems remain elusive. Here, we studied the microbial communities of the rhizosphere and endophytic microbes of the dominant plant species across the Inner Mongolian steppes using metagenomic sequencing and investigated their relationships with changes in mean annual temperature (MAT) and mean annual precipitation (MAP). Metagenomic sequencing based on Illumina high-throughput sequencing, using the paired end method to construct a small fragment library for sequencing. Adaptation of root systems to the environment affected the composition and function of rhizosphere and endophytic microbial communities. However, these communities exhibited distinct community assembly and environmental adaptation patterns. Both rhizosphere and endophytic microbial communities can be divided into two unrelated systems based on their ecological niches. The composition and function of the rhizosphere microbial communities were mainly influenced by MAT, while those of the endophytic microbial communities were mainly influenced by MAP. MAT affected the growth, reproduction, and lipid decomposition of rhizosphere microorganisms, whereas MAP affected reverse transcription and cell wall/membrane/envelope biogenic functions of endophytic microorganisms. Our findings reveal the composition and function of the rhizosphere and endophytic microbial communities in response to changes in MAP and MAT, which has important implications for future biogeography and climate change research.