For example, Gilgamesh was a historical king, but the Epic of Gilgamesh is clearly largely fictional. Do we have any way of knowing whether or not ancient Mesopotamians considered it a true account?
We are limited by our sources. When there are many and varied sources available, we can use historical practice and methods to try to more accuratly gauge the historicity of a certain secondary or even primary source. This is why we distinguish between primary, secondary and even tertiary sources. It's also why we need to try and uncover how a specific source came to us and why the author was motivated to produce this source. Primary sources are the various objects created during the time you are trying to do research on. They can be extremely useful when trying to determine the historicity of an event, but even when using primary sources, the researcher needs to be very much aware of how these sources came into being and how they were transferred to us. For example, a text or object made from a more practical motivation will often contain simply but possible fairly accurate information. The problem is that these kind of documents can be very rare for certain periods in time and that they will often contain very limited information, often void of context. However, when we combine such documents with more literary sources or even secondary sources, we can see if these sources corroberate eachother. This is a very crude and overly simplified explanation of how historical practice works, but I think it sufficiently covers the basics.
On to your actual question. When you want to know what people thought about the historicity of literary works, your body of available and relevant sources shrinks tremendously. The sheer lack of historical evidence on this subject makes this a very daunting task. How can we know what these people thought about such a work? The easiest way is through ego-documents which refer to literary works, preferably from the period you are studying and refering the work in question. However, I'm not sure how common these documents are for this period in time. Given that the Epic of Gilgamesh is considered to be one of the first literary works, I doubt if such sources are available. You'd have to ask an expert. You could try and gain insight into their worldview in order to estimate how "real" these stories were to contemporaries by combining every remotly relevant source, comparative research and anthropological theories. I'm not sure if any of this has been done, or atleast if it has been done convincingly. Lacking an abundance of sources, most conclusions would probably rely heavily on anthropological theories and would remain, atleast in part, conjecture from a historiographical point of view.