pub struct ToolError { /* private fields */ }Expand description
Error type for tool handlers that supports the ? operator.
This type can be created from any error that implements Display,
allowing idiomatic Rust error handling in tool handlers.
§Example
ⓘ
use turbomcp_core::response::ToolError;
async fn handler(path: String) -> Result<String, ToolError> {
// Use ? operator - errors automatically convert to ToolError
let file = std::fs::read_to_string(&path)?;
Ok(format!("Read {} bytes", file.len()))
}
// Create errors manually
async fn validate(value: i32) -> Result<String, ToolError> {
if value < 0 {
return Err(ToolError::new("Value must be non-negative"));
}
Ok("Valid".into())
}Implementations§
Trait Implementations§
Source§impl Error for ToolError
Available on crate feature std only.
impl Error for ToolError
Available on crate feature
std only.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<FromUtf8Error> for ToolError
Available on crate feature std only.
impl From<FromUtf8Error> for ToolError
Available on crate feature
std only.Source§fn from(e: FromUtf8Error) -> ToolError
fn from(e: FromUtf8Error) -> ToolError
Converts to this type from the input type.
Source§impl From<ParseFloatError> for ToolError
Available on crate feature std only.
impl From<ParseFloatError> for ToolError
Available on crate feature
std only.Source§fn from(e: ParseFloatError) -> ToolError
fn from(e: ParseFloatError) -> ToolError
Converts to this type from the input type.
Source§impl From<ParseIntError> for ToolError
Available on crate feature std only.
impl From<ParseIntError> for ToolError
Available on crate feature
std only.Source§fn from(e: ParseIntError) -> ToolError
fn from(e: ParseIntError) -> ToolError
Converts to this type from the input type.
Source§impl IntoToolResponse for ToolError
impl IntoToolResponse for ToolError
Source§fn into_tool_response(self) -> CallToolResult
fn into_tool_response(self) -> CallToolResult
Convert this type into a
CallToolResultAuto Trait Implementations§
impl Freeze for ToolError
impl RefUnwindSafe for ToolError
impl Send for ToolError
impl Sync for ToolError
impl Unpin for ToolError
impl UnsafeUnpin for ToolError
impl UnwindSafe for ToolError
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