In endoscopic retrograde cholangiopancreatography (ERCP), an endoscope (a flexible viewing tube), is inserted into the mouth and through the stomach into the duodenum (the first segment of the small intestine). Then a contrast agent (a liquid that can be seen on x-rays) is injected into the biliary tract through the sphincter of Oddi. The dye outlines any blockage.
Surgical instruments can also be passed through the endoscope, allowing a doctor to remove a stone in a bile duct or insert a tube (stent) to bypass a blockage in the duct that is caused by a stone, scarring, or cancer.