#[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
mcp and tools only.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> FmtForward for T
impl<T> FmtForward for T
Sourceยงfn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Sourceยงfn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Sourceยงfn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Sourceยงfn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Sourceยงfn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Sourceยงfn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Sourceยงfn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Sourceยงfn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreimpl<T> MaybeSend for Twhere
T: Send,
Sourceยงimpl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Sourceยงfn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Sourceยงfn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSourceยงfn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSourceยงfn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Sourceยงfn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Sourceยงfn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Sourceยงfn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Sourceยงfn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Sourceยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Sourceยงimpl<T> Tap for T
impl<T> Tap for T
Sourceยงfn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSourceยงfn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSourceยงfn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSourceยงfn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSourceยงfn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSourceยงfn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSourceยงfn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Sourceยงfn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Sourceยงfn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Sourceยงfn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Sourceยงfn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Sourceยงfn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Sourceยงfn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.