The burgeoning need for extensive data processing has sparked enthusiasm for development of a novel optical logic gate platform due to the constraints of current electronic logic gates in achieving precise and rapid computations. In this study, junction field-effect phototransistors based on MoS2/Ge heterojunctions are constructed as optical logic units. This device demonstrates a positive photoresponse that is attributed to the photoconductivity effect occurring upon irradiation with visible light (< 800 nm). Under the illumination of near infrared optics with wavelengths (800-1800 nm) within the communication band, the device shows a negative photoresponse, which is associated with the interlayer exciton effect. A current state of the device can be effectively modulated as different logical states by precisely tuning the wavelength and power density of the optical devices. Within a 3×3 MoS2/Ge phototransistor array, five essentially all-optical logic gates (“AND”, “OR”, “NAND”, “NOT” and “NOR”) can be achieved in every signal unit. Furthermore, three complex all-optical logical operations (Y = A·B + C, Y = A·B + B·C + A·C and Y = A·B + C) are demonstrated by integrating two MoS2/Ge phototransistors in series. Compared to electronic designs, these all-optical logic operations based on the MoS2/Ge phototransistor offer a significant reduction in transistor number, with savings of 50-94% when implementing the abovementioned functions. These results offer valuable insights into the potential of silicon-based optical logical circuits and present opportunities for the development of photonic chips with low power consumption, high fidelity and large volumes.