#[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,
) -> CreateMessageRequestParams
pub fn new( messages: Vec<SamplingMessage>, max_tokens: u32, ) -> CreateMessageRequestParams
Create a new CreateMessageRequestParams with required fields.
Sourcepub fn with_model_preferences(
self,
model_preferences: ModelPreferences,
) -> CreateMessageRequestParams
pub fn with_model_preferences( self, model_preferences: ModelPreferences, ) -> CreateMessageRequestParams
Set model preferences.
Sourcepub fn with_system_prompt(
self,
system_prompt: impl Into<String>,
) -> CreateMessageRequestParams
pub fn with_system_prompt( self, system_prompt: impl Into<String>, ) -> CreateMessageRequestParams
Set system prompt.
Sourcepub fn with_include_context(
self,
include_context: ContextInclusion,
) -> CreateMessageRequestParams
pub fn with_include_context( self, include_context: ContextInclusion, ) -> CreateMessageRequestParams
Set include context.
Sourcepub fn with_temperature(self, temperature: f32) -> CreateMessageRequestParams
pub fn with_temperature(self, temperature: f32) -> CreateMessageRequestParams
Set temperature.
Sourcepub fn with_stop_sequences(
self,
stop_sequences: Vec<String>,
) -> CreateMessageRequestParams
pub fn with_stop_sequences( self, stop_sequences: Vec<String>, ) -> CreateMessageRequestParams
Set stop sequences.
Sourcepub fn with_metadata(self, metadata: Value) -> CreateMessageRequestParams
pub fn with_metadata(self, metadata: Value) -> CreateMessageRequestParams
Set metadata.
Sourcepub fn with_tools(self, tools: Vec<Tool>) -> CreateMessageRequestParams
pub fn with_tools(self, tools: Vec<Tool>) -> CreateMessageRequestParams
Set tools.
Sourcepub fn with_tool_choice(
self,
tool_choice: ToolChoice,
) -> CreateMessageRequestParams
pub fn with_tool_choice( self, tool_choice: ToolChoice, ) -> CreateMessageRequestParams
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<CreateMessageRequestParams, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CreateMessageRequestParams, <__D as Deserializer<'de>>::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)Sourceยงfn meta_or_default(&mut self) -> &mut RequestMetaObject
fn meta_or_default(&mut self) -> &mut RequestMetaObject
Sourceยงimpl Serialize for CreateMessageRequestParams
impl Serialize for CreateMessageRequestParams
Sourceยงfn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for CreateMessageRequestParams
Auto Trait Implementationsยง
impl Freeze for CreateMessageRequestParams
impl RefUnwindSafe for CreateMessageRequestParams
impl Send for CreateMessageRequestParams
impl Sync for CreateMessageRequestParams
impl Unpin for CreateMessageRequestParams
impl UnsafeUnpin for CreateMessageRequestParams
impl UnwindSafe for CreateMessageRequestParams
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงfn in_current_span(self) -> Instrumented<Self> โ
fn in_current_span(self) -> Instrumented<Self> โ
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more