First: Shimano GRX road/gravel derailleurs and shifters are NOT compatible with the mountain derailleurs (XT, XTR, etc). So an XT shifter will not work with a GRX derailleur.
The GRX and other road bottom brackets are only offered in 68mm and 70mm widths so they will not fit a mountain bike's bottom bracket which is 73mm.
The XT has a 73mm bottom bracket which is standard for mountain bikes and it can be installed with two 2.5mm spacers onto a road/gravel frame that has a 68mm bottom bracket shell. This is how my commuting bike is setup. BUT this pushes the chainrings farther out to the right so I needed a mountain front derailleur to shift onto the big ring.
The GRX front derailleur may not be able to push the chain far enough to the right to work on a mountain bike. Again this would be due to the 73mm bottom bracket.
So to answer your question fully one needs to know the bottom bracket width: 68mm or 73mm?
For the best compatibility and fewest issues I would recommend using parts intended for the specific bike. If the bike has a 68mm BB shell then I'd suggest the GRX. If it's 73mm then I'd suggest XT.
Another factor which may influence your final choice is the gear ratio options for highest and lowest gear. Road/Gravel gearing is significantly higher than mountain bike gear ratios.