Identifying switches and sensors (for home automation config)

If you simply want a single sketch to load onto all your Mega's with a fixed config then maybe you can write code that reads the mac address from the shield on startup and configures itself appropriately. This requires no external storage but its obviously not re-configurable on the fly. Its also going to have the problem that you will have to update code if you have to replace a shield or something else changes.

If you want a system that can be re-configured on the fly then you have a harder task. As far as I can tell an MQTT broker cannot easily obtain the IP or MAC address of the client. You may find this thread useful as an alternative.

If you can overcome that particular issue then the retrieval of information from google docs and caching on whatever machine you are using as your local MQTT broker shouldnt really be that hard. If you provide more detail in what you are trying to achieve you are likely to get more detailed answers.