@@ -1418,6 +1418,78 @@ impl std::error::Error for CallToolError {
1418
1418
}
1419
1419
}
1420
1420
1421
+ /// Conversion of `CallToolError` into a `CallToolResult` with an error.
1422
+ impl From < CallToolError > for CallToolResult {
1423
+ fn from ( value : CallToolError ) -> Self {
1424
+ // Convert `CallToolError` to a `CallToolResult` by using the `with_error` method
1425
+ CallToolResult :: with_error ( value)
1426
+ }
1427
+ }
1428
+
1429
+ impl CallToolResult {
1430
+ /// Create a `CallToolResult` with an error, containing an error message in the content
1431
+ pub fn with_error ( error : CallToolError ) -> Self {
1432
+ Self {
1433
+ content : vec ! [ CallToolResultContentItem :: TextContent ( TextContent :: new(
1434
+ None ,
1435
+ error. to_string( ) , // Convert the error to a string and wrap it in TextContent
1436
+ ) ) ] ,
1437
+ is_error : Some ( true ) , // Indicate that the result is an error
1438
+ meta : None ,
1439
+ }
1440
+ }
1441
+
1442
+ /// Create a `CallToolResult` containing text content and optional annotations
1443
+ pub fn text_content ( text_content : String , text_annotations : Option < TextContentAnnotations > ) -> Self {
1444
+ Self {
1445
+ content : vec ! [ TextContent :: new( text_annotations, text_content) . into( ) ] ,
1446
+ is_error : None ,
1447
+ meta : None ,
1448
+ }
1449
+ }
1450
+
1451
+ /// Create a `CallToolResult` containing image content, with data, MIME type, and optional annotations
1452
+ pub fn image_content ( data : String , mime_type : String , annotations : Option < ImageContentAnnotations > ) -> Self {
1453
+ Self {
1454
+ content : vec ! [ ImageContent :: new( annotations, data, mime_type) . into( ) ] ,
1455
+ is_error : None ,
1456
+ meta : None ,
1457
+ }
1458
+ }
1459
+
1460
+ /// Create a `CallToolResult` containing an embedded resource, with optional annotations
1461
+ pub fn embedded_resource ( resource : EmbeddedResourceResource , annotations : Option < EmbeddedResourceAnnotations > ) -> Self {
1462
+ Self {
1463
+ content : vec ! [ EmbeddedResource :: new( annotations, resource) . into( ) ] ,
1464
+ is_error : None ,
1465
+ meta : None ,
1466
+ }
1467
+ }
1468
+
1469
+ // Add metadata to the `CallToolResult`, allowing additional context or information to be included
1470
+ pub fn with_meta ( mut self , meta : Option < serde_json:: Map < String , Value > > ) -> Self {
1471
+ self . meta = meta;
1472
+ self
1473
+ }
1474
+ }
1475
+
1476
+ impl CallToolResultContentItem {
1477
+ /// Create a `CallToolResultContentItem` with text content and optional annotations
1478
+ pub fn text_content ( test_content : String , annotations : Option < TextContentAnnotations > ) -> Self {
1479
+ TextContent :: new ( annotations, test_content) . into ( )
1480
+ }
1481
+
1482
+ /// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
1483
+ pub fn image_content ( data : String , mime_type : String , annotations : Option < ImageContentAnnotations > ) -> Self {
1484
+ ImageContent :: new ( annotations, data, mime_type) . into ( )
1485
+ }
1486
+
1487
+ /// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
1488
+ pub fn embedded_resource ( resource : EmbeddedResourceResource , annotations : Option < EmbeddedResourceAnnotations > ) -> Self {
1489
+ EmbeddedResource :: new ( annotations, resource) . into ( )
1490
+ }
1491
+ }
1492
+
1421
1493
/// BEGIN AUTO GENERATED
1422
1494
impl :: serde:: Serialize for ClientJsonrpcRequest {
1423
1495
fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
0 commit comments