I know that a lot of the concept comes from ancient Greece and Hippocrates, but is there evidence that it was an older idea perhaps connected to Egypt or Mesopotamia?
Most standard histories locate the origins of humoral theory in the Hippocratic-Galenic tradition. For instance:
Historically, humoralism formed the basis for the Western tradition of medicine down to the nineteenth century. In its earliest manifestations, in sixth- and fifth-century BC Greece, it reveals no links with any of the medical systems elsewhere in the eastern Mediterranean,and the few apparent parallels with Indian or Far Eastern medical systems may well be fortuitous.
Vivian Nutton (1997) Humoralism. In WF Bynum and R Porter (eds), Companion Encyclopedia of the History of Medicine. London & New York: Routledge, p. 281
However, some of the concepts underlying humoral theory can be found in other traditions. The influence that other medical cultures may have had on the humoral system is a point of debate.
It was ... the literate Hippocratic-Galenic tradition that produced, eventually, the 'classic' system of four humours. Its durability and dominance in Europe - in scholarship as much as medicine - ensured the projection of 'humours' onto other medical currents such as Ayurveda.
It would have of course been open to us to begin further east so as to counteract that project. It would also have been possible to begin elsewhere, and earlier, in the Eastern Mediterranean and Middle East. The belief for example implied in some Egyptian medical writings, that disease was caused by corrupt residues in the body, bears some resemblances to Hippocratic physiology. So does the emphasis in Babylonian medicine on fluids as a determinant of health. In neither medical culture was anything resembling a humour articulated into a full disease aetiology. On the other hand, underlying conceptions of ill health as caused by disruption of the natural order have been detected in ancient Mesopotamiam culture. And, strikingly, maat (balance, order, justice), a concept with its eponymous goddess, seems to have been central to Egyptian medicine. Health depended on the 'balanced' flow of substances along the twenty-two mtw or vessels, as described in the Ebers papyrus, irrigating it by their passage as the Nile's waters irrigated the land.
How far the Greeks knew about, and were receptive to, these other medicines is a matter of continuing scholarly argument.
Peregrine Horden (2013) Introduction. In Peregrine Horden and Elisabeth Hsu (eds) The Body in Balance: Humoral Medicines in Practice. London & New York: Berghahn Books, pp. 6-7