I'd be assuming it would be British or European history, middle ages or so. Where have these stories come from in fact? Were there ever people who had such jobs or was it based on advisors to kings? or?
The idea of a court magician stems in part from real-life positions such as court astrologers, alchemists, and the like, as well as less-official positions attached to the court. Dr. John Dee, for example, was the court astrologer to Elizabeth I, and Dee's associate Edward Kelley was patronized as an alchemist by Rudolph II. As far as the ultimate origins of the practice, it's hard to trace. There are historical records of rulers drawing to themselves advisers and others of influence; there are records of ancient Egyptian and Sumerian rulers consulting priests, exorcists, astrologers, etc. and fictional versions of these individuals and their exploits were evident in the records like the stories in the Westcar Papyrus.
To expand on this a bit in the European court context, let me steal a bit from an earlier answer:
Was there a court wizard or something like it?
Not often explicitly, but Edward Peters notes in The Magician, The Witch, and the Law:
It has been said of the court of Louis the pious, son of Charlemagne, that every great man at it had his own personal astrologer. The texture of Carolingian court life suggests the plausibility of this remark, because in the heady atmosphere of transforming an Iron Age assembly of warbands and settlers into an ideal Christian kingdom, the Carolingian Empire often presents (as it did to itself) the image of a composite of late Roman imperial and barbarian Germanic styles of life and thought. the classical works that Carolingian scholars discovered, edited, and circulated among themselves were the very ones that managed to preserve much antiquarianism along with Christian piety. The religious basis of Charlemagne's and Louis's renovatio has long been recognized. What has often not been recognized as fully is how much of the old learned world of late antiquity came with the Christian materials. In the sophisticated, learned, violent, and self-serving Carolingian court world those who had access to, and even a rudimentary understanding of, learned magic could easily find employers. No residual pagan superstitions or folk beliefs were necessary. The Carolingian aristocrats knew how to value learned magicians as it valued learned chroniclers, holy men, astrologers, wandering Irish scholar monks, and any other successful means of making their way through the rapidly changing post-tribal world of Charlemagne's renewed Roman Empire and Louis's rapidly deteriorating Christian kingdom.
Even if not formally holding a position at court, the concentration of money and politics often created a demi-monde were magicians could thrive; in 17th century France for example, you had characters like La Voisin, who reputedly peddled poisons, love potions, abortions, fortune-telling, and black masses to the royalty of the court of Louis XIV.