Linking of MeSH terms and genes
I think you could use the MESH.db package in Bioconductor to annotate your genes. I have never used, but you should be able to do something like:

library("MeSH.db")
select(MeSH.db, keys = myGenes, keytype = "ENTREZ", columns = "MESH")


It depends on the MeSHDbi package from which you could retrieve other data form that database if needed