pub struct Json<T>(pub T);Expand description
Extract and deserialize JSON arguments into a typed struct.
This extractor deserializes the tool’s JSON arguments into type T.
The type must implement serde::de::DeserializeOwned and schemars::JsonSchema.
§Example
use tower_mcp::extract::Json;
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Debug, Deserialize, JsonSchema)]
struct MyInput {
name: String,
count: i32,
}
// In an extractor handler:
// |Json(input): Json<MyInput>| async move { ... }§Rejection
Returns a JsonRejection if deserialization fails. The rejection contains
the error message and potentially the path to the failing field.
Tuple Fields§
§0: TTrait Implementations§
Source§impl<S, T> FromToolRequest<S> for Json<T>where
T: DeserializeOwned,
impl<S, T> FromToolRequest<S> for Json<T>where
T: DeserializeOwned,
Source§type Rejection = JsonRejection
type Rejection = JsonRejection
The rejection type returned when extraction fails.
Source§fn from_tool_request(
_ctx: &RequestContext,
_state: &S,
args: &Value,
) -> Result<Self, Self::Rejection>
fn from_tool_request( _ctx: &RequestContext, _state: &S, args: &Value, ) -> Result<Self, Self::Rejection>
Extract this type from the tool request. Read more
impl<T: Copy> Copy for Json<T>
Auto Trait Implementations§
impl<T> Freeze for Json<T>where
T: Freeze,
impl<T> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T> Send for Json<T>where
T: Send,
impl<T> Sync for Json<T>where
T: Sync,
impl<T> Unpin for Json<T>where
T: Unpin,
impl<T> UnwindSafe for Json<T>where
T: 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