Probably not, but the wording is ambiguous and up to the DM
The closest parallel is that of the Sentinel Feat. The mechanics are very similar and both utilize the expenditure of your reaction. The feat itself states (emphasis mine):
When a creature within 5 feet of you makes an attack against a target other than you (and that target doesn't have this feat), you can use your reaction to make a melee weapon attack against the attacking creature.
The main differences between Sentinel's wording and The Mechanical Servant is:
[Sentinel] When a creature within 5 feet of you makes an attack...
[Mechanical Servant] If you are the target of a melee attack
Sentinel goes on to utilize the same target term, but ultimately they are very similar in that you have an opportunity to use a reaction when an enemy targets/attacks.
Wording Maybe...Intent No
We do have a previous question on Can Sentinel interrupt an enemy's attack? where the answer there, along with a tweet from Jeremy Crawford, says that is not the intent.
Targeting vs Attacking
Because there really isn't a separate targeting mechanic for melee attacks, it makes it hard to create a mechanical trigger that isn't based on something within the rules. I think that this is where Crawford was going with his ruling that you have to let the triggering event complete - which is the attack (of which targeting is a part of...not separate from.)
Order of events
The requirement for the trigger to complete is how we get to the order of events.
If we go by Crawford's intent, the the Artificer must wait for the attack to complete before using the reaction (does not stop the attack.)
If you go by your own ruling that you can do so once the enemy has 'targeted' but not actually rolled an attack, then you can utilize your reaction before the enemy rolls their attack.
Up to the DM
Because of the ambiguity in the RAW, and not withstanding Crawford's intent clarification, I think it's safe to leave this up to the DM.
Personally, I like the idea of interrupting the attack - but it may be too powerful. Let the DM decide how they want to run it, but make sure to stay consistent in the ruling - or communicate a change if you feel it's not working and why.