Abstract Gastric environment is an extreme pH and enzyme-rich condition, which together with gastric mucus barrier and short retention time of oral medicine militate against effective oral drug delivery to lesion areas of gastric diseases. Assembly, especially shape-control assembly of magnetic nanoparticles potentially helps the site-selective drug molecule delivery. However, the harsh gastric condition, and cumbersome and strict requirements make the in situ reversible assembly remain challenging. Herein, synergistically pepsin-bridged and magnetic field-mediated morphological control of magnetic-graphitic-nanocapsules (MGNs) needle assembly (MNA) is developed in stomach for prolonged gastric retention and enhanced mucus penetration. The MNAs with good biocompatibility, large magnetic moments and unique needle-shape are formed with the help of pepsin, demonstrating superior magnetic-driven capability to overcome gastric mucus barrier. Molecular dynamics simulations reveal binding modes between MGN and amino acid residues on either side of the pepsin, indicating pepsin acts as “bridge” allowing sufficient contact among MGNs and further facilitates the needle assembly. Moreover, anticancer drug doxorubicin (DOX)-loaded MNAs demonstrate superior targeted cancer cell killing ability and boosted DOX penetration in a mouse model, which promises good bioavailability of drug molecules. The versatile MNA-based platform offers a robust strategy for effective oral drug delivery and site-selective therapy of gastric diseases.