def METHOD_NAME(
    task_ins: TaskIns, exclude_reconnect_ins: bool
) -> Optional[ServerMessage]:
    """Get ServerMessage from TaskIns, if available."""
    # Return the message if it is in
    # {GetPropertiesIns, GetParametersIns, FitIns, EvaluateIns}
    # Return the message if it is ReconnectIns and exclude_reconnect_ins is False.
    if not validate_task_ins(
        task_ins, discard_reconnect_ins=exclude_reconnect_ins
    ) or not task_ins.task.HasField("legacy_server_message"):
        return None
    return task_ins.task.legacy_server_message