New in version: 2.0.0
MCP servers can request LLM completions from clients. The client handles these requests through a sampling handler callback.
Sampling Handler
Provide asampling_handler function when creating the client:
Handler Parameters
The sampling handler receives three parameters:Basic Example
If the client doesn’t provide a sampling handler, servers can optionally configure a fallback handler. See Server Sampling for details.

