2.0.0
Use this when you need to respond to server requests for LLM completions.
MCP servers can request LLM completions from clients during tool execution. This enables servers to delegate AI reasoning to the client, which controls which LLM is used and how requests are made.
Handler Template
Handler Parameters
SamplingParams
Server preferences for model selection (hints, cost/speed/intelligence priorities)
Built-in Handlers
FastMCP provides built-in handlers for OpenAI, Anthropic, and Google Gemini APIs that support the full sampling API including tool use.OpenAI Handler
New in version2.11.0
Install the OpenAI handler with
pip install fastmcp[openai].Anthropic Handler
New in version2.14.1
Install the Anthropic handler with
pip install fastmcp[anthropic].Google Gemini Handler
New in version3.1.0
Install the Google Gemini handler with
pip install fastmcp[gemini].Sampling Capabilities
When you provide asampling_handler, FastMCP automatically advertises full sampling capabilities to the server, including tool support. To disable tool support for simpler handlers: