The Internet of Things (IoT) enables billions of smart devices to capture, process, and transform data to improve decision-making. IoT demands a critical mobile edge computing (MEC) ecosystem to provide dependability. It requires an efficient and distributed architecture with multiple IoT communication protocols. In this way, intelligent middleware is needed to achieve the efficiency, throughput, and reliability of data delivery on different protocols without interference from the local setup of the device. This paper proposes a modular and interoperable middleware called MiddleFog to select the most appropriate communication protocol among MQTT and CoAP dynamically. Also, the approach minimizes communication limitations caused by latency, package loss, and low network throughput between MEC and Cloud. The initial evaluations show a message loss rate lower than 25% for small messages, and performance improves around 48% for medium-sized delivery messages.