Skip to main content
Sampling lets your server ask the client to run an LLM and return a completion while a tool is executing. This enables tools to leverage AI for analysis and generation without the client having to orchestrate multiple tool calls.

Basic usage

Parameters

Sampling requests are expressed as CreateMessageRequestParams (field names match the MCP schema, e.g. maxTokens, systemPrompt).

Response

request_sampling(...) returns a CreateMessageResult. Most clients return TextContent:

Multi-turn conversations

Pass a list of messages for multi-turn context:

Example: Code review

Error handling

Sampling requires the client to advertise the sampling capability. If the client doesn’t support sampling, request_sampling(...) raises McpError (typically METHOD_NOT_FOUND):
Last modified on June 30, 2026