pub struct CreateMessageParams {
pub messages: Vec<SamplingMessage>,
pub max_tokens: u32,
pub system_prompt: Option<String>,
pub temperature: Option<f64>,
pub stop_sequences: Vec<String>,
pub model_preferences: Option<ModelPreferences>,
pub include_context: Option<IncludeContext>,
pub metadata: Option<Map<String, Value>>,
pub tools: Option<Vec<SamplingTool>>,
pub tool_choice: Option<ToolChoice>,
pub task: Option<TaskRequestParams>,
pub meta: Option<Value>,
}Expand description
Parameters for a sampling/createMessage request.
§Deprecated in MCP 2026-07-28
Sampling is Deprecated by SEP-2577. It remains part of the specification and is still served here, but new implementations should not adopt it, and existing ones should migrate before its earliest removal: the first specification revision released on or after 2027-07-28.
The documented migration path is to integrate with an LLM provider’s API directly rather than asking the client to sample on the server’s behalf.
Nothing is removed from this crate on that date. Removal from the specification does not oblige an SDK to drop a feature, and this crate’s own support follows its release policy, not the specification’s calendar.
Fields§
§messages: Vec<SamplingMessage>The messages to send to the LLM
max_tokens: u32Maximum number of tokens to generate
system_prompt: Option<String>Optional system prompt
temperature: Option<f64>Sampling temperature (0.0 to 1.0)
stop_sequences: Vec<String>Stop sequences
model_preferences: Option<ModelPreferences>Model preferences
include_context: Option<IncludeContext>Context inclusion mode
metadata: Option<Map<String, Value>>Additional metadata
tools: Option<Vec<SamplingTool>>Tools available for the model to use (SEP-1577)
tool_choice: Option<ToolChoice>Tool choice mode (SEP-1577)
task: Option<TaskRequestParams>Legacy 2025-11-25 task parameters for async execution.
This field is invalid on the 2026-07-28 protocol.
meta: Option<Value>Optional protocol-level metadata
Implementations§
Source§impl CreateMessageParams
impl CreateMessageParams
Sourcepub fn new(
messages: Vec<SamplingMessage>,
max_tokens: u32,
) -> CreateMessageParams
pub fn new( messages: Vec<SamplingMessage>, max_tokens: u32, ) -> CreateMessageParams
Create a new sampling request
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> CreateMessageParams
pub fn system_prompt(self, prompt: impl Into<String>) -> CreateMessageParams
Set the system prompt
Sourcepub fn temperature(self, temp: f64) -> CreateMessageParams
pub fn temperature(self, temp: f64) -> CreateMessageParams
Set the temperature
Sourcepub fn stop_sequence(self, seq: impl Into<String>) -> CreateMessageParams
pub fn stop_sequence(self, seq: impl Into<String>) -> CreateMessageParams
Add a stop sequence
Sourcepub fn model_preferences(self, prefs: ModelPreferences) -> CreateMessageParams
pub fn model_preferences(self, prefs: ModelPreferences) -> CreateMessageParams
Set model preferences
Sourcepub fn include_context(self, mode: IncludeContext) -> CreateMessageParams
pub fn include_context(self, mode: IncludeContext) -> CreateMessageParams
Set context inclusion mode
Sourcepub fn tools(self, tools: Vec<SamplingTool>) -> CreateMessageParams
pub fn tools(self, tools: Vec<SamplingTool>) -> CreateMessageParams
Set tools available for the model to use (SEP-1577)
Sourcepub fn tool_choice(self, choice: ToolChoice) -> CreateMessageParams
pub fn tool_choice(self, choice: ToolChoice) -> CreateMessageParams
Set tool choice mode (SEP-1577)
Trait Implementations§
Source§impl Clone for CreateMessageParams
impl Clone for CreateMessageParams
Source§fn clone(&self) -> CreateMessageParams
fn clone(&self) -> CreateMessageParams
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more