Overview
Returns a function to request LLM completions from the host via MCPsampling/createMessage. The host decides which model to use and may modify or reject the request.
Check getHostCapabilities()?.sampling before calling. For tool-augmented completions, check ?.sampling?.tools.
Import
Signature
CreateSamplingMessageParams
Standard MCPCreateMessageRequest params:
SamplingMessage[]
required
Conversation messages to send to the model.
number
required
Maximum tokens in the response.
string
System prompt for the model.
number
Sampling temperature.
Tool[]
Tools the model can call. When provided, the result may include
tool_use blocks.Returns
(params) => Promise<CreateMessageResult | CreateMessageResultWithTools | undefined>
Function to request an LLM completion.
CreateMessageResult
string
Model used by the host.
string
Response role (typically
"assistant").Content
Response content block.
string
Why the model stopped (
"endTurn", "toolUse", etc.).