@@ -1410,6 +1410,19 @@ impl From<CallToolError> for RpcError {
14101410 }
14111411}
14121412
1413+ /// Conversion of `CallToolError` into a `CallToolResult` with an error.
1414+ impl From < CallToolError > for CallToolResult {
1415+ fn from ( value : CallToolError ) -> Self {
1416+ // Convert `CallToolError` to a `CallToolResult`
1417+ CallToolResult {
1418+ content : vec ! [ TextContent :: new( value. to_string( ) , None , None ) . into( ) ] ,
1419+ is_error : Some ( true ) ,
1420+ meta : None ,
1421+ structured_content : None ,
1422+ }
1423+ }
1424+ }
1425+
14131426// Implement `Display` for `CallToolError` to provide a user-friendly error message.
14141427impl core:: fmt:: Display for CallToolError {
14151428 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
@@ -1437,6 +1450,12 @@ impl CallToolRequest {
14371450 }
14381451}
14391452
1453+ impl < T : Into < String > > From < T > for TextContent {
1454+ fn from ( value : T ) -> Self {
1455+ TextContent :: new ( value. into ( ) , None , None )
1456+ }
1457+ }
1458+
14401459#[ deprecated( since = "0.4.0" , note = "This trait was renamed to RpcMessage. Use RpcMessage instead." ) ]
14411460pub type RPCMessage = ( ) ;
14421461#[ deprecated( since = "0.4.0" , note = "This trait was renamed to McpMessage. Use McpMessage instead." ) ]
@@ -3770,6 +3789,70 @@ impl ContentBlock {
37703789 }
37713790 }
37723791}
3792+ impl CallToolResult {
3793+ pub fn text_content ( content : Vec < TextContent > ) -> Self {
3794+ Self {
3795+ content : content. into_iter ( ) . map ( Into :: into) . collect ( ) ,
3796+ is_error : None ,
3797+ meta : None ,
3798+ structured_content : None ,
3799+ }
3800+ }
3801+ pub fn image_content ( content : Vec < ImageContent > ) -> Self {
3802+ Self {
3803+ content : content. into_iter ( ) . map ( Into :: into) . collect ( ) ,
3804+ is_error : None ,
3805+ meta : None ,
3806+ structured_content : None ,
3807+ }
3808+ }
3809+ pub fn audio_content ( content : Vec < AudioContent > ) -> Self {
3810+ Self {
3811+ content : content. into_iter ( ) . map ( Into :: into) . collect ( ) ,
3812+ is_error : None ,
3813+ meta : None ,
3814+ structured_content : None ,
3815+ }
3816+ }
3817+ pub fn resource_link ( content : Vec < ResourceLink > ) -> Self {
3818+ Self {
3819+ content : content. into_iter ( ) . map ( Into :: into) . collect ( ) ,
3820+ is_error : None ,
3821+ meta : None ,
3822+ structured_content : None ,
3823+ }
3824+ }
3825+ pub fn embedded_resource ( content : Vec < EmbeddedResource > ) -> Self {
3826+ Self {
3827+ content : content. into_iter ( ) . map ( Into :: into) . collect ( ) ,
3828+ is_error : None ,
3829+ meta : None ,
3830+ structured_content : None ,
3831+ }
3832+ }
3833+ /// Create a `CallToolResult` with an error, containing an error message in the content
3834+ pub fn with_error ( error : CallToolError ) -> Self {
3835+ Self {
3836+ content : vec ! [ ContentBlock :: TextContent ( TextContent :: new( error. to_string( ) , None , None ) ) ] ,
3837+ is_error : Some ( true ) ,
3838+ meta : None ,
3839+ structured_content : None ,
3840+ }
3841+ }
3842+ /// Assigns metadata to the CallToolResult, enabling the inclusion of extra context or details.
3843+ pub fn with_meta ( mut self , meta : Option < serde_json:: Map < String , Value > > ) -> Self {
3844+ self . meta = meta;
3845+ self
3846+ }
3847+ /// Assigns structured_content to the CallToolResult
3848+ pub fn with_structured_content (
3849+ mut self ,
3850+ structured_content : :: serde_json:: Map < :: std:: string:: String , :: serde_json:: Value > ,
3851+ ) -> Self {
3852+ self . structured_content = Some ( structured_content) ;
3853+ self
3854+ }
3855+ }
37733856/// END AUTO GENERATED
37743857#[ cfg( test) ]
37753858mod tests {
0 commit comments