pub struct CallToolResult {
pub content: Vec<Annotated<RawContent>>,
pub structured_content: Option<Value>,
pub is_error: Option<bool>,
pub meta: Option<Meta>,
}Expand description
The result of a tool call operation.
Contains the content returned by the tool execution and an optional flag indicating whether the operation resulted in an error.
Fields§
§content: Vec<Annotated<RawContent>>The content returned by the tool (text, images, etc.)
structured_content: Option<Value>An optional JSON object that represents the structured result of the tool call
is_error: Option<bool>Whether this result represents an error condition
meta: Option<Meta>Optional protocol-level metadata for this result
Implementations§
Source§impl CallToolResult
impl CallToolResult
Sourcepub fn success(content: Vec<Annotated<RawContent>>) -> CallToolResult
pub fn success(content: Vec<Annotated<RawContent>>) -> CallToolResult
Create a successful tool result with unstructured content
Sourcepub fn error(content: Vec<Annotated<RawContent>>) -> CallToolResult
pub fn error(content: Vec<Annotated<RawContent>>) -> CallToolResult
Create an error tool result with unstructured content
Sourcepub fn structured(value: Value) -> CallToolResult
pub fn structured(value: Value) -> CallToolResult
Sourcepub fn structured_error(value: Value) -> CallToolResult
pub fn structured_error(value: Value) -> CallToolResult
Create an error tool result with structured content
§Example
use rmcp::model::CallToolResult;
use serde_json::json;
let result = CallToolResult::structured_error(json!({
"error_code": "INVALID_INPUT",
"message": "Temperature value out of range",
"details": {
"min": -50,
"max": 50,
"provided": 100
}
}));Sourcepub fn into_typed<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn into_typed<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Convert the structured_content part of response into a certain type.
§About json schema validation
Since rust is a strong type language, we don’t need to do json schema validation here.
But if you do have to validate the response data, you can use jsonschema crate.
Trait Implementations§
Source§impl Clone for CallToolResult
impl Clone for CallToolResult
Source§fn clone(&self) -> CallToolResult
fn clone(&self) -> CallToolResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CallToolResult
impl Debug for CallToolResult
Source§impl<'de> Deserialize<'de> for CallToolResult
impl<'de> Deserialize<'de> for CallToolResult
Source§fn deserialize<D>(
deserializer: D,
) -> Result<CallToolResult, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<CallToolResult, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl PartialEq for CallToolResult
impl PartialEq for CallToolResult
Source§impl Serialize for CallToolResult
impl Serialize for CallToolResult
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 CallToolResult
Auto Trait Implementations§
impl Freeze for CallToolResult
impl RefUnwindSafe for CallToolResult
impl Send for CallToolResult
impl Sync for CallToolResult
impl Unpin for CallToolResult
impl UnsafeUnpin for CallToolResult
impl UnwindSafe for CallToolResult
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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