It’s happening at run/prompt time. If you’ve used function calling from OpenAI it’s basically the same thing (they’ve just standardised the format)

So, with MCP, LLMs are aware of various “tools” and will interact with them mid-conversation to expand their capabilities.

In your “generating code” example, the LLM would have to generate the code and then run the code everytime you want to interact with a tool - would be really impractical and inefficient … plus it could produce an erroneous implementation each time.