A device, system and method for diagnosing and treating gastric disorders is provided. A functional device resides within the patient's stomach and is secured to the stomach wall by an attachment device. The functional device may be a sensor for sensing various parameters of the stomach or stomach environment, or may be a therapeutic delivery device. The functional device in one embodiment provides a device, system and method for gastric electrical stimulation where stimulating electrodes are secured to the wall of the stomach by the attachment device or otherwise. A preferred device includes: at least one stimulating electrode in electrical contact with the stomach wall; an electronics unit containing the electronic circuitry of the device; and an attachment mechanism for attaching the device to the stomach wall. The functional devices may be programmed to respond to sensed information or signals. An endoscopic delivery system delivers the functional device through the esophagus and into the stomach where it is attached the stomach wall. The endoscopic instruments attach or remove the attachment devices and functional devices from the stomach and may be used to assist in determining the optimal attachment location.