How does MCAS communicate with other systems to know if the flaps are retracted or not?
MCAS is implemented on the Flight Control Computers (FCCs). The FCCs communicate over an aviation data bus, ARINC format. The B737NG used ARINC 700 series standard for communication - sensor information is linked to the FCCs via the avionics data bus. The B737MAX may or may not use a later standard ARINC bus.

There are two FCCs on the B737MAX. From this link:


  Computer redundancy. As of 2019, the two flight control computers of Boeing 737 never cross-checked each other's operations; i.e., each was a single non-redundant channel. This lack of robustness existed since the early implementation and persisted for decades. The updated flight control system will use both flight control computers and compare their outputs. This switch to a fail-safe two-channel redundant system, with each computer using an independent set of sensors, is a radical change from the architecture used on 737s since the introduction on the older model 737-300 in the 1980s. Up to the MAX in its prior to groundings version, the system alternates between computers after each flight.[191] The two computers architecture allowed switching in flight if the operating computer failed, thus increasing availability. In the revised architecture, Boeing required the two computers to monitor each other so that each one can vet the other.


So not only do the FCCs know if the flaps are retracted, they now know if their computations correlate.