intermediateMCP Advanced — Sampling, Elicitation, Resources, Prompts

What is MCP 'sampling', and why is it a notably different direction of control flow than a normal tool call?

Sampling lets an MCP SERVER ask the CLIENT's LLM to generate a completion on the server's behalf — inverting the usual direction where the client always initiates. This lets a server perform its own AI-driven logic (like summarizing something internally) while borrowing the client's already-configured model access rather than needing its own API key.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is 'elicitation' in MCP, and what user experience problem does it solve?← Back to all Spring AI questions