Skip to main content

MCP Sampling

Sampling allows MCP servers to request LLM completions from clients. This enables servers to leverage the client’s LLM capabilities for text generation, with support for tool calling.

Protocol Version

This feature implements MCP Protocol Version 2025-11-25.

Tool Choice Modes

Python API

Basic Sampling

Sampling with Tools

Tool Choice Factory Methods

Model Preferences

Custom Callback

MCP Protocol Messages

Sampling Request

Sampling Response

Response with Tool Use

Stop Reasons

Best Practices

  1. Set appropriate max_tokens - Avoid unnecessary token usage
  2. Use model preferences - Guide model selection
  3. Handle tool calls - Process and respond to tool use
  4. Provide system prompts - Set context for better responses