The mass of the proton and the neutron is determined, essentially, by QCD. There’s nothing obscure about it, just a very hard calculation, using numerical methods, that have now become practical. No issue of principle exists.
The reason gravitational effects are irrelevant is that the RHS of Einstein’s equations is, essentially, proportional to the ratio of the typical energy of the process diivided by the Planck scale. The typical energy of processes involving the proton and the neutron at atomic scales is much iess than their rest energy, i.e. around 1 GeV; the Planck scale energy is around 10^19 GeV, so the ratio is about 10^(-19), completely negligible. Spacetime around atoms is flat.
What you say is really very important, you say "The modern image of a proton is a sea of quarks and gluons described by QCD with three valence quarks: two up- and one down-quark. A natural question which arises in this picture is: how many quarks and how many gluons is a proton?"
But for me it could be the proof that the proton is a black hole because the cosmological black holes are also made up of a sea of neutrons piled up by the force of gravity. Or I'm thinking of another alternative is that it could have a sea of primitive protons each containing one down quark and two up quarks.