What is MCP Sampling?
MCP Sampling is a Model Context Protocol capability that allows an MCP Server to request language-model generation through the MCP Host or Client under user and client control.
Quick Facts
| Specification | Official Specification |
|---|
How It Works
MCP Sampling reverses the usual direction of model invocation. Instead of only the host calling server tools, a server can ask the host to perform a model completion for a specific purpose. This is useful when a server needs LLM assistance but should not hold model credentials or directly call a provider. Sampling must be treated carefully because it can amplify trust issues: the host should review the request, apply policy, preserve user consent, and avoid letting a server silently steer the model outside the user's intent.
Key Characteristics
- Server-initiated request: lets an MCP Server ask the host side for model generation
- Credential separation: avoids giving every MCP Server direct access to model provider keys
- Policy-controlled: should remain subject to host, client, and user approval rules
- Context-sensitive: sampling requests may include messages, system intent, and constraints
- Security-sensitive: untrusted servers must not be allowed to manipulate model behavior silently
Common Use Cases
- An MCP Server asking the host model to summarize retrieved records before returning them
- A tool integration requesting model help to transform data into a user-readable explanation
- Keeping model credentials centralized in the host rather than distributed across servers
- Applying user-visible policy checks before a server-initiated generation occurs
- Building advanced server workflows that need LLM reasoning without owning the LLM runtime
Example
Loading code...Frequently Asked Questions
Why does MCP Sampling exist?
It allows servers to request model assistance without directly owning model credentials or bypassing host policy. The host remains the control point for model access.
Is Sampling the same as a tool call?
No. A tool call asks a server to perform an operation. Sampling asks the host side to perform language-model generation on behalf of a server request.
What should a host check before allowing Sampling?
The host should check server trust, user intent, request content, data sensitivity, model policy, token budget, and whether the request should be visible to or approved by the user.
Can Sampling create security risks?
Yes. A malicious or compromised server could try to influence model behavior, leak data through prompts, or generate misleading instructions. Hosts should apply strict policy and logging.