@@ -236,6 +236,11 @@ impl ClientMessage {
236
236
pub fn is_initialize_request ( & self ) -> bool {
237
237
matches ! ( self , Self :: Request ( request) if request. request. is_initialize_request( ) )
238
238
}
239
+
240
+ /// Returns `true` if the message is an `InitializedNotification`
241
+ pub fn is_initialized_notification ( & self ) -> bool {
242
+ matches ! ( self , Self :: Notification ( notofication) if notofication. notification. is_initialized_notification( ) )
243
+ }
239
244
}
240
245
241
246
impl From < ClientJsonrpcNotification > for ClientMessage {
@@ -519,7 +524,7 @@ impl TryFrom<NotificationFromClient> for ClientNotification {
519
524
}
520
525
521
526
impl NotificationFromClient {
522
- /// Checks if the current notification is an `InitializedNotification` from the client, indicating that the client has been initialized.
527
+ /// Returns `true` if the message is an `InitializedNotification`
523
528
pub fn is_initialized_notification ( & self ) -> bool {
524
529
matches ! (
525
530
self ,
@@ -1318,10 +1323,15 @@ pub enum MessageFromClient {
1318
1323
}
1319
1324
1320
1325
impl MessageFromClient {
1321
- /// Returns `true` if the request is an `InitializeRequest`.
1326
+ /// Returns `true` if the message is an `InitializeRequest`.
1322
1327
pub fn is_initialize_request ( & self ) -> bool {
1323
1328
matches ! ( self , Self :: RequestFromClient ( request) if request. is_initialize_request( ) )
1324
1329
}
1330
+
1331
+ /// Returns `true` if the message is an `InitializedNotification`
1332
+ pub fn is_initialized_notification ( & self ) -> bool {
1333
+ matches ! ( self , Self :: NotificationFromClient ( notofication) if notofication. is_initialized_notification( ) )
1334
+ }
1325
1335
}
1326
1336
1327
1337
impl From < RequestFromClient > for MessageFromClient {
@@ -1450,12 +1460,60 @@ impl CallToolError {
1450
1460
}
1451
1461
1452
1462
/// Specific constructor to create a `CallToolError` for an `UnknownTool` error.
1453
- pub fn unknown_tool ( tool_name : String ) -> Self {
1463
+ pub fn unknown_tool ( tool_name : impl Into < String > ) -> Self {
1454
1464
// Create a `CallToolError` from an `UnknownTool` error (wrapped in a `Box`).
1455
- CallToolError ( Box :: new ( UnknownTool ( tool_name) ) )
1465
+ CallToolError ( Box :: new ( UnknownTool ( tool_name. into ( ) ) ) )
1466
+ }
1467
+
1468
+ pub fn invalid_arguments ( tool_name : impl Into < String > , message : Option < impl Into < String > > ) -> Self {
1469
+ let tool_name = tool_name. into ( ) ;
1470
+ let message = message. map ( |m| m. into ( ) ) ;
1471
+
1472
+ let full_message = match message {
1473
+ Some ( msg) => format ! ( "Invalid arguments for tool '{tool_name}': {msg}" ) ,
1474
+ None => format ! ( "Invalid arguments for tool '{tool_name}'" ) ,
1475
+ } ;
1476
+ Self :: from_message ( full_message)
1477
+ }
1478
+
1479
+ /// Creates a new `CallToolError` from a string message.
1480
+ ///
1481
+ /// This is useful for generating ad-hoc or one-off errors without defining a custom error type.
1482
+ /// Internally, it wraps the string in a lightweight error type that implements the `Error` trait.
1483
+ ///
1484
+ /// # Examples
1485
+ ///
1486
+ /// ```
1487
+ /// let err = CallToolError::from_message("Something went wrong");
1488
+ /// println!("{:?}", err);
1489
+ /// ```
1490
+ ///
1491
+ /// # Parameters
1492
+ ///
1493
+ /// - `message`: Any type that can be converted into a `String` (e.g., `&str` or `String`)
1494
+ ///
1495
+ /// # Returns
1496
+ ///
1497
+ /// A `CallToolError` wrapping a dynamic error created from the provided message.
1498
+ pub fn from_message ( message : impl Into < String > ) -> Self {
1499
+ struct MsgError ( String ) ;
1500
+ impl std:: fmt:: Debug for MsgError {
1501
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1502
+ write ! ( f, "{}" , self . 0 )
1503
+ }
1504
+ }
1505
+ impl std:: fmt:: Display for MsgError {
1506
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1507
+ write ! ( f, "{}" , self . 0 )
1508
+ }
1509
+ }
1510
+ impl std:: error:: Error for MsgError { }
1511
+
1512
+ CallToolError :: new ( MsgError ( message. into ( ) ) )
1456
1513
}
1457
1514
}
1458
1515
1516
+
1459
1517
/// Converts a `CallToolError` into a `RpcError`.
1460
1518
///
1461
1519
/// The conversion creates an internal error variant of `RpcError`
@@ -1508,8 +1566,6 @@ impl<T: Into<String>> From<T> for TextContent {
1508
1566
}
1509
1567
}
1510
1568
1511
-
1512
-
1513
1569
#[ derive( serde:: Serialize , serde:: Deserialize , Debug , Clone ) ]
1514
1570
#[ serde( untagged) ]
1515
1571
#[ allow( clippy:: large_enum_variant) ]
@@ -1568,8 +1624,6 @@ impl Display for ClientMessages {
1568
1624
}
1569
1625
}
1570
1626
1571
-
1572
-
1573
1627
#[ derive( serde:: Serialize , serde:: Deserialize , Debug , Clone ) ]
1574
1628
#[ serde( untagged) ]
1575
1629
#[ allow( clippy:: large_enum_variant) ]
@@ -1628,8 +1682,6 @@ impl Display for ServerMessages {
1628
1682
}
1629
1683
}
1630
1684
1631
-
1632
-
1633
1685
#[ derive( serde:: Serialize , serde:: Deserialize , Debug , Clone ) ]
1634
1686
#[ serde( untagged) ]
1635
1687
#[ allow( clippy:: large_enum_variant) ]
0 commit comments