<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _create_handler_directory(self, handler_name, api_version, server_type):
 """Create a directory for the handler and add an index inside"""


        directory = "{}/api/v{}/{}/{}".format(self._directory, api_version, server_type, handler_name)
        os.makedirs(directory, exist_ok=True)

        with open("{}/api/v{}/{}/{}.rst".format(self._directory, api_version, server_type, handler_name), "w+") as f:
            f.write(handler_name.replace("api.", "").replace("_", " ", ).capitalize())
            f.write("\n-----------------------------\n\n")
            f.write(".. toctree::\n   :glob:\n   :maxdepth: 2\n\n   {}/*\n".format(handler_name))