pub struct Parameters<P>(pub P);Available on crate feature
server only.Expand description
Parameter extractor for tools and prompts
When used in tool and prompt handlers, this wrapper extracts and deserializes
parameters from the incoming request. The framework will automatically parse
the JSON arguments from tool calls or prompt arguments and deserialize them
into the specified type P.
The #[serde(transparent)] attribute ensures that the wrapper doesn’t add
an extra layer in the JSON structure - it directly delegates serialization
and deserialization to the inner type P.
§Usage
Use Parameters<T> as a parameter in your tool or prompt handler functions:
#[derive(Deserialize, JsonSchema)]
struct CalculationRequest {
operation: String,
a: f64,
b: f64,
}
// In a tool handler
async fn calculate(params: Parameters<CalculationRequest>) -> Result<String, String> {
let request = params.0; // Extract the inner value
match request.operation.as_str() {
"add" => Ok((request.a + request.b).to_string()),
_ => Err("Unknown operation".to_string()),
}
}The framework handles the extraction automatically:
- For tools: Parses the
argumentsfield from tool call requests - For prompts: Parses the
argumentsfield from prompt requests - Returns appropriate error responses if deserialization fails
Tuple Fields§
§0: PTrait Implementations§
Source§impl<P: Clone> Clone for Parameters<P>
impl<P: Clone> Clone for Parameters<P>
Source§fn clone(&self) -> Parameters<P>
fn clone(&self) -> Parameters<P>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<P: Debug> Debug for Parameters<P>
impl<P: Debug> Debug for Parameters<P>
Source§impl<'de, P> Deserialize<'de> for Parameters<P>where
P: Deserialize<'de>,
impl<'de, P> Deserialize<'de> for Parameters<P>where
P: Deserialize<'de>,
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<S, P> FromContextPart<PromptContext<'_, S>> for Parameters<P>where
P: DeserializeOwned,
impl<S, P> FromContextPart<PromptContext<'_, S>> for Parameters<P>where
P: DeserializeOwned,
fn from_context_part( context: &mut PromptContext<'_, S>, ) -> Result<Self, ErrorData>
Source§impl<S, P> FromContextPart<ToolCallContext<'_, S>> for Parameters<P>where
P: DeserializeOwned,
impl<S, P> FromContextPart<ToolCallContext<'_, S>> for Parameters<P>where
P: DeserializeOwned,
fn from_context_part( context: &mut ToolCallContext<'_, S>, ) -> Result<Self, ErrorData>
Source§impl<P: JsonSchema> JsonSchema for Parameters<P>
impl<P: JsonSchema> JsonSchema for Parameters<P>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreAuto Trait Implementations§
impl<P> Freeze for Parameters<P>where
P: Freeze,
impl<P> RefUnwindSafe for Parameters<P>where
P: RefUnwindSafe,
impl<P> Send for Parameters<P>where
P: Send,
impl<P> Sync for Parameters<P>where
P: Sync,
impl<P> Unpin for Parameters<P>where
P: Unpin,
impl<P> UnwindSafe for Parameters<P>where
P: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
Set the “status” flags for the
self file descriptor. Read moreSource§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>
Converts
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>
Converts
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