Skip to main content

CreateMessageRequestParams

Struct CreateMessageRequestParams 

Source
#[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>, }
๐Ÿ‘ŽDeprecated since 2.0.0:

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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
ยงmeta: Option<RequestMetaObject>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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: u32
๐Ÿ‘ŽDeprecated since 2.0.0:

Sampling 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>>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>>
๐Ÿ‘ŽDeprecated since 2.0.0:

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>
๐Ÿ‘ŽDeprecated since 2.0.0:

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

Source

pub fn new(messages: Vec<SamplingMessage>, max_tokens: u32) -> Self

Create a new CreateMessageRequestParams with required fields.

Source

pub fn with_model_preferences(self, model_preferences: ModelPreferences) -> Self

Set model preferences.

Source

pub fn with_system_prompt(self, system_prompt: impl Into<String>) -> Self

Set system prompt.

Source

pub fn with_include_context(self, include_context: ContextInclusion) -> Self

Set include context.

Source

pub fn with_temperature(self, temperature: f32) -> Self

Set temperature.

Source

pub fn with_stop_sequences(self, stop_sequences: Vec<String>) -> Self

Set stop sequences.

Source

pub fn with_metadata(self, metadata: Value) -> Self

Set metadata.

Source

pub fn with_tools(self, tools: Vec<Tool>) -> Self

Set tools.

Source

pub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self

Set tool choice.

Source

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

Sourceยง

fn clone(&self) -> CreateMessageRequestParams

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for CreateMessageRequestParams

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for CreateMessageRequestParams

Sourceยง

fn default() -> CreateMessageRequestParams

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<'de> Deserialize<'de> for CreateMessageRequestParams

Sourceยง

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl JsonSchema for CreateMessageRequestParams

Sourceยง

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Sourceยง

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Sourceยง

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Sourceยง

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Sourceยง

impl PartialEq for CreateMessageRequestParams

Sourceยง

fn eq(&self, other: &CreateMessageRequestParams) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Sourceยง

impl RequestParamsMeta for CreateMessageRequestParams

Sourceยง

fn meta(&self) -> Option<&RequestMetaObject>

Get a reference to the meta field
Sourceยง

fn meta_mut(&mut self) -> &mut Option<RequestMetaObject>

Get a mutable reference to the meta field
Sourceยง

fn set_meta(&mut self, meta: RequestMetaObject)

Set the meta field
Sourceยง

fn progress_token(&self) -> Option<ProgressToken>

Get the progress token from meta, if present
Sourceยง

fn set_progress_token(&mut self, token: ProgressToken)

Set a progress token in meta
Sourceยง

fn traceparent(&self) -> Option<&str>

Get the W3C traceparent value from meta, if present (SEP-414)
Sourceยง

fn set_traceparent(&mut self, value: &str)

Set the W3C traceparent value in meta (SEP-414)
Sourceยง

fn tracestate(&self) -> Option<&str>

Get the W3C tracestate value from meta, if present (SEP-414)
Sourceยง

fn set_tracestate(&mut self, value: &str)

Set the W3C tracestate value in meta (SEP-414)
Sourceยง

fn baggage(&self) -> Option<&str>

Get the W3C baggage value from meta, if present (SEP-414)
Sourceยง

fn set_baggage(&mut self, value: &str)

Set the W3C baggage value in meta (SEP-414)
Sourceยง

fn meta_or_default(&mut self) -> &mut RequestMetaObject

Get a mutable reference to meta, inserting an empty one if absent.
Sourceยง

impl Serialize for CreateMessageRequestParams

Sourceยง

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Sourceยง

impl StructuralPartialEq for CreateMessageRequestParams

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Sourceยง

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Sourceยง

impl<T> DynClone for T
where T: Clone,

Sourceยง

fn __clone_box(&self, _: Private) -> *mut ()

Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> PolicyExt for T
where T: ?Sized,

Sourceยง

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Sourceยง

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Sourceยง

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more