If you are performing raycast from the script, intersect_ray function returns exactly what you are looking for. Here is an example with mouse click:
func _input(event):
if event is InputEventMouseButton and event.is_pressed():
var worldspace = get_world_3d().direct_space_state
var start = camera.project_ray_origin(event.position)
var end = camera.project_position(event.position, 1000)
var params = PhysicsRayQueryParameters3D.new()
params.from = start
params.to = end
var result = worldspace.intersect_ray(params)
if (result != null and result.size() > 0):
print(result["normal"])