The endoscope is inserted through a natural opening. The doctor may simply make a diagnosis. They may also take a sample of tissue (biopsy) for later analysis in a laboratory.
Alternatively, your doctor could perform minor surgery at the same time. For example, they may place a stent across an obstructing tumour or remove a stone from a bile duct. Once the endoscopy is complete, the endoscope is removed.