notice that the nearest point on the surface of the sphere is situated along the line connecting the point to the center of the sphere thus without loss of generality assuming that the sphere is centered at (0,0,0) we get

massDesity = 2 - sqrt(x^2 + y^2 + z^2)

in order to find the total mass you have to integrate the above expression over the volume of the sphere (use spherical parametrization)...