I would recommend taking a look at the Mongoose Networking library.
It's a lightweight open-source networking library designed specifically for embedded systems. It includes full support for most networking protocols, including MQTT. With the MQTT support, you can build not just a client, but also a MQTT broker. The library is highly portable and has support for a wide variety of microcontrollers and platforms. It can run on a baremetal environment or with an RTOS like FreeRTOS or Zephyr.
Mongoose has a solid documentation of all its features and usages and you can find an example of building a MQTT simple server here.
Heads up: I am part of the Mongoose development team. Hope this solves your problem!