The microbiome and the brain both influence each other bidirectionally, that is to say that they influence each other in the same ways.
To start, we can discuss neurotransmitters. The microbiome is capable of making neurotransmitters; notably, it can synthesis serotonin out of the amino acid tryptophan. These created neurotransmitters can influence the highly innervated intestinal lining, which sends signals up to the brain via the Vagus nerve. The Vagus nerve can send down signals as well, releasing chemicals and hormones that can influence the microbiome both positively and negatively.
Additionally, there is the possibility that the two influence each other by way of inflammation. Various mental health conditions are associated with systemic inflammation, as are various dysbioses. On top of that, both of these types of maladies can actually cause inflammation, either by way of cortisol/stress hormones or by way of expressed metabolites entering the bloodstream. There is further evidence that these inflammations are intertwined, as mitigating the cause of one can help alleviate the symptoms of the other.
There may yet be more ways that the microbiome interfaces with the brain, but right now there hasn’t been enough solid research linking the two to really draw any heavy conclusions.