Molla Mohammad Mehdi Neraqi were both notable jurists in Kashan who died concurrently with the birth of their son. The son was given his father's name, as was common at the time. In Kashan, naming a son after one's father was customary. When this boy grew up to be a brilliant scholar and lawyer, the Kashan people called him "Agha Koochak," which means "Young Sir," and his father "Agha Bozorg," which means "Great Sir," because their names were similar.
While visiting Isfahan, the Qajar Shah, Mohammad Shah, also made a visit to Kashan, where he had meetings with the city's notables and thinkers, among them Molla Mohammad Mehdi, popularly known as "Agha Koochak". Because of the scholar's eminence, the Shah commanded that Kashan residents refer to him as "Agha Bozorg". Additionally, he gave the city's ruler, Haj Mohammad Taghi Khanban, orders to build this mosque and school and married "Agha Bozorg" to his daughter.