#[non_exhaustive]pub struct CallToolResult {
pub content: Vec<Content>,
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 (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.content: Vec<Content>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<Content>) -> Self
pub fn success(content: Vec<Content>) -> Self
Create a successful tool result with unstructured content
Sourcepub fn error(content: Vec<Content>) -> Self
pub fn error(content: Vec<Content>) -> Self
Create an error tool result with unstructured content
Sourcepub fn structured(value: Value) -> Self
pub fn structured(value: Value) -> Self
Sourcepub fn structured_error(value: Value) -> Self
pub fn structured_error(value: Value) -> Self
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 Default for CallToolResult
impl Default for CallToolResult
Source§fn default() -> CallToolResult
fn default() -> CallToolResult
Source§impl<'de> Deserialize<'de> for CallToolResult
impl<'de> Deserialize<'de> for CallToolResult
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>,
Source§impl From<CallToolResult> for ServerResult
impl From<CallToolResult> for ServerResult
Source§fn from(value: CallToolResult) -> Self
fn from(value: CallToolResult) -> Self
Source§impl IntoCallToolResult for CallToolResult
Available on crate feature server only.
impl IntoCallToolResult for CallToolResult
server only.fn into_call_tool_result(self) -> Result<CallToolResult, ErrorData>
Source§impl JsonSchema for CallToolResult
impl JsonSchema for CallToolResult
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 more