M-dwarf stars are promising targets for identifying and characterizing potentially habitable planets. K2-3 is a nearby (45 pc), early-type M dwarf hosting three small transiting planets, the outermost of which orbits close to the inner edge of the stellar (optimistic) habitable zone. The K2-3 system is well suited for follow-up characterization studies aimed at determining accurate masses and bulk densities of the three planets. Using a total of 329 radial velocity measurements collected over 2.5 years with the HARPS-N and HARPS spectrographs and a proper treatment of the stellar activity signal, we aim to improve measurements of the masses and bulk densities of the K2-3 planets. We use our results to investigate the physical structure of the planets. We analyse radial velocity time series extracted with two independent pipelines by using Gaussian process regression. We adopt a quasi-periodic kernel to model the stellar magnetic activity jointly with the planetary signals. We use Monte Carlo simulations to investigate the robustness of our mass measurements of K2-3,c and K2-3,d, and to explore how additional high-cadence radial velocity observations might improve them. Despite the stellar activity component being the strongest signal present in the radial velocity time series, we are able to derive masses for both planet b ($M_{rm b}=6.6pm1.1$ $M_{rm oplus}$) and planet c ($M_{rm c}=3.1^{+1.3}_{-1.2}$ $M_{rm oplus}$). The Doppler signal due to K2-3,d remains undetected, likely because of its low amplitude compared to the radial velocity signal induced by the stellar activity. The closeness of the orbital period of K2-3,d to the stellar rotation period could also make the detection of the planetary signal complicated. [...]