Skip to main content
Sampling allows MCP tools to request LLM completions during their execution.

Configuration

To enable sampling, provide a sampling_callback function when initializing the MCPClient:

Creating Sampling-Enabled Tools

When building MCP servers, tools can request sampling using the context parameter:

Error Handling

If no sampling callback is provided but a tool requests sampling: