Like I said, you're not being charged anything there. It comes out of the purchase price.
It's the agent who is listing the house at a price and sourcing the various inspectors and appraisers. They're putting in the work to sell your house at a price point.
So, if the agent can manage to move your house for $2 million rather than $1 million, why shouldn't they get a larger reward?
It's a different scenario from servers. Servers can't convince you to pay more for an item or for the business to sell that item for less. Real estate agents can.
Indeed, for the seller this makes sense and the agent's and seller's incentives are aligned. But there's a nasty externality created where real estate agents contribute to a constant upward pressure on housing prices. This eventually helps make housing unaffordable.
Agent commission is just shy of 6%. And that's for both the selling and buying agent. So they each get around 3%. For all the work you could be doing maximizing a house's selling price to get another $1k or $2k, you could be closing another house and getting another $10k.