Why sampling exists
Most server features provide something to the client. Sampling reverses that direction: the server asks the client to use its model. A server may use sampling to:- Summarize a long resource
- Interpret logs or error messages
- Extract structured data from text
- Generate an intermediate plan
- Analyze content as one step in a larger workflow
- Implement a controlled agentic loop
How MCP sampling works
A typical sampling flow is:- During initialization, the client declares the
samplingcapability. - The server sends a
sampling/createMessagerequest. - The client reviews the messages and parameters.
- The client may modify, reject, or ask the user to approve the request.
- The client selects a model and requests a generation.
- The client reviews the generated result.
- The client returns an approved result to the server.
What is in a sampling request?
A request can include:- Conversation messages
- A system prompt
- Model preferences
- A maximum token count
- Stop sequences
- Temperature and other optional generation settings
- Metadata
- Tools when both sides support tool-enabled sampling
Who controls sampling?
The MCP specification recommends keeping a human in the loop. Applications should let users inspect, edit, approve, or reject sampling requests and review results.
Sampling vs tool calls
Sampling and tools move in opposite directions.
A server can combine both concepts. For example, it can call sampling to interpret an error and then return a suggested recovery plan as its tool result.
Tool-enabled sampling
The current MCP specification allows clients to declare support for tools inside sampling. A server can then include tool definitions and tool-choice preferences in a sampling request. This feature supports multi-step model interactions, but it is capability-dependent. Servers must not send tool-enabled sampling requests to clients that did not declare the required support.Security and privacy
Sampling requests can contain sensitive instructions or data. Clients should:- Show the user what the server wants to send
- Minimize unnecessary context
- Prevent hidden access to full conversation history
- Apply model-provider and organizational policies
- Filter or reject unsafe requests
- Review results before returning them
- Avoid exposing credentials in prompts or responses