#[non_exhaustive]pub struct CreateMessageRequestParams {
pub meta: Option<RequestMetaObject>,
pub messages: Vec<SamplingMessage>,
pub model_preferences: Option<ModelPreferences>,
pub system_prompt: Option<String>,
pub include_context: Option<ContextInclusion>,
pub temperature: Option<f32>,
pub max_tokens: u32,
pub stop_sequences: Option<Vec<String>>,
pub metadata: Option<Value>,
pub tools: Option<Vec<Tool>>,
pub tool_choice: Option<ToolChoice>,
}Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Expand description
Parameters for creating a message through LLM sampling.
This structure contains all the necessary information for a client to generate an LLM response, including conversation history, model preferences, and generation parameters.
This implements TaskAugmentedRequestParamsMeta as sampling requests can be
long-running and may benefit from task-based execution.
Fields (Non-exhaustive)ยง
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.meta: Option<RequestMetaObject>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Protocol-level metadata for this request (SEP-1319)
messages: Vec<SamplingMessage>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
The conversation history and current messages
model_preferences: Option<ModelPreferences>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Preferences for model selection and behavior
system_prompt: Option<String>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
System prompt to guide the modelโs behavior
include_context: Option<ContextInclusion>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
How much context to include from MCP servers
temperature: Option<f32>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Temperature for controlling randomness (0.0 to 1.0)
max_tokens: u32Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Maximum number of tokens to generate
stop_sequences: Option<Vec<String>>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Sequences that should stop generation
metadata: Option<Value>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Additional metadata for the request
tools: Option<Vec<Tool>>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Tools available for the model to call (SEP-1577)
tool_choice: Option<ToolChoice>Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
Tool selection behavior (SEP-1577)
Implementationsยง
Sourceยงimpl CreateMessageRequestParams
impl CreateMessageRequestParams
Sourcepub fn new(messages: Vec<SamplingMessage>, max_tokens: u32) -> Self
pub fn new(messages: Vec<SamplingMessage>, max_tokens: u32) -> Self
Create a new CreateMessageRequestParams with required fields.
Sourcepub fn with_model_preferences(self, model_preferences: ModelPreferences) -> Self
pub fn with_model_preferences(self, model_preferences: ModelPreferences) -> Self
Set model preferences.
Sourcepub fn with_system_prompt(self, system_prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, system_prompt: impl Into<String>) -> Self
Set system prompt.
Sourcepub fn with_include_context(self, include_context: ContextInclusion) -> Self
pub fn with_include_context(self, include_context: ContextInclusion) -> Self
Set include context.
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Set temperature.
Sourcepub fn with_stop_sequences(self, stop_sequences: Vec<String>) -> Self
pub fn with_stop_sequences(self, stop_sequences: Vec<String>) -> Self
Set stop sequences.
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
Set metadata.
Sourcepub fn with_tools(self, tools: Vec<Tool>) -> Self
pub fn with_tools(self, tools: Vec<Tool>) -> Self
Set tools.
Sourcepub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
pub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
Set tool choice.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate the sampling request parameters per SEP-1577 spec requirements.
Checks:
- ToolUse content is only allowed in assistant messages
- ToolResult content is only allowed in user messages
- Messages with tool result content MUST NOT contain other content types
- Every assistant ToolUse must be balanced with a corresponding user ToolResult
Trait Implementationsยง
Sourceยงimpl Clone for CreateMessageRequestParams
impl Clone for CreateMessageRequestParams
Sourceยงfn clone(&self) -> CreateMessageRequestParams
fn clone(&self) -> CreateMessageRequestParams
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSourceยงimpl Debug for CreateMessageRequestParams
impl Debug for CreateMessageRequestParams
Sourceยงimpl Default for CreateMessageRequestParams
impl Default for CreateMessageRequestParams
Sourceยงfn default() -> CreateMessageRequestParams
fn default() -> CreateMessageRequestParams
Sourceยงimpl<'de> Deserialize<'de> for CreateMessageRequestParams
impl<'de> Deserialize<'de> for CreateMessageRequestParams
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Sourceยงimpl JsonSchema for CreateMessageRequestParams
impl JsonSchema for CreateMessageRequestParams
Sourceยงfn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Sourceยงfn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Sourceยงfn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSourceยงimpl RequestParamsMeta for CreateMessageRequestParams
impl RequestParamsMeta for CreateMessageRequestParams
Sourceยงfn meta(&self) -> Option<&RequestMetaObject>
fn meta(&self) -> Option<&RequestMetaObject>
Sourceยงfn meta_mut(&mut self) -> &mut Option<RequestMetaObject>
fn meta_mut(&mut self) -> &mut Option<RequestMetaObject>
Sourceยงfn set_meta(&mut self, meta: RequestMetaObject)
fn set_meta(&mut self, meta: RequestMetaObject)
Sourceยงfn progress_token(&self) -> Option<ProgressToken>
fn progress_token(&self) -> Option<ProgressToken>
Sourceยงfn set_progress_token(&mut self, token: ProgressToken)
fn set_progress_token(&mut self, token: ProgressToken)
Sourceยงfn traceparent(&self) -> Option<&str>
fn traceparent(&self) -> Option<&str>
traceparent value from meta, if present (SEP-414)Sourceยงfn set_traceparent(&mut self, value: &str)
fn set_traceparent(&mut self, value: &str)
traceparent value in meta (SEP-414)Sourceยงfn tracestate(&self) -> Option<&str>
fn tracestate(&self) -> Option<&str>
tracestate value from meta, if present (SEP-414)Sourceยงfn set_tracestate(&mut self, value: &str)
fn set_tracestate(&mut self, value: &str)
tracestate value in meta (SEP-414)Sourceยงfn set_baggage(&mut self, value: &str)
fn set_baggage(&mut self, value: &str)
baggage value in meta (SEP-414)