While he was a bastard, James was soon to be Mary's closest family member by the time she came to sit on her throne. He was the bastard son of Mary's father King James V of Scotland and not able to be King himself. He had the power of regent until Mary returned.
And her brother is often the only person she could trust. Though she had to exile him after a plan went wrong against John Knox. Though he eventually makes his way back into the life of his royal half-sister. He is present in Scottish politics when she is dethroned as Queen in the place of her infant son King James VI.
While I liked his character on the show, I really doubt the two siblings were that friendly in reality. Before Mary became a "guest" (more like prisoner) of Elizabeth I of England, she lost a civil war with James leading the opposing force against her own. He became regent for Mary's son James VI, though he is assassinated by a partisan loyal to the Mary of reality. His CW incarnation presumably met the same fate but we never got that far.