Gastrointestinal endoscopy, upper GI endoscopy, gastroscopy, esophagoscopy or endoscopy) is a procedure that allows a doctor to diagnose and treat problems in the upper gastrointestinal (UGI) tract. To perform the procedure, the doctor uses a long, flexible, lighted tube called an endoscope. The endoscope is guided through the patient’s mouth and throat, then through the esophagus, stomach and duodenum (first part of the small intestine). The physician can examine the inside of these organs and detect abnormalities.