Skip to content

Commit 99986de

Browse files
authored
chore: update function argument types to improve flexibility and type (#87)
* chore: updated function argument types to improve flexibility and type safety. * chore: update for 11-05 * fix: clippy issues
1 parent 83734bf commit 99986de

File tree

4 files changed

+64
-34
lines changed

4 files changed

+64
-34
lines changed

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,14 +1465,22 @@ impl CallToolError {
14651465
CallToolError(Box::new(UnknownTool(tool_name.into())))
14661466
}
14671467

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-
};
1468+
/// Creates a `CallToolError` for invalid arguments with optional details.
1469+
///
1470+
pub fn invalid_arguments(tool_name: impl AsRef<str>, message: Option<String>) -> Self {
1471+
// Trim tool_name to remove whitespace and check for emptiness
1472+
let tool_name = tool_name.as_ref().trim();
1473+
if tool_name.is_empty() {
1474+
return Self::from_message("Invalid arguments: tool name cannot be empty".to_string());
1475+
}
1476+
1477+
// Use a descriptive default message if none provided
1478+
let default_message = "no additional details provided".to_string();
1479+
let message = message.unwrap_or(default_message);
1480+
1481+
// Format the full error message
1482+
let full_message = format!("Invalid arguments for tool '{tool_name}': {message}");
1483+
14761484
Self::from_message(full_message)
14771485
}
14781486

@@ -1513,7 +1521,6 @@ impl CallToolError {
15131521
}
15141522
}
15151523

1516-
15171524
/// Converts a `CallToolError` into a `RpcError`.
15181525
///
15191526
/// The conversion creates an internal error variant of `RpcError`

src/generated_schema/2025_03_26/schema_utils.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,14 +1465,22 @@ impl CallToolError {
14651465
CallToolError(Box::new(UnknownTool(tool_name.into())))
14661466
}
14671467

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-
};
1468+
/// Creates a `CallToolError` for invalid arguments with optional details.
1469+
///
1470+
pub fn invalid_arguments(tool_name: impl AsRef<str>, message: Option<String>) -> Self {
1471+
// Trim tool_name to remove whitespace and check for emptiness
1472+
let tool_name = tool_name.as_ref().trim();
1473+
if tool_name.is_empty() {
1474+
return Self::from_message("Invalid arguments: tool name cannot be empty".to_string());
1475+
}
1476+
1477+
// Use a descriptive default message if none provided
1478+
let default_message = "no additional details provided".to_string();
1479+
let message = message.unwrap_or(default_message);
1480+
1481+
// Format the full error message
1482+
let full_message = format!("Invalid arguments for tool '{tool_name}': {message}");
1483+
14761484
Self::from_message(full_message)
14771485
}
14781486

@@ -1513,7 +1521,6 @@ impl CallToolError {
15131521
}
15141522
}
15151523

1516-
15171524
/// Converts a `CallToolError` into a `RpcError`.
15181525
///
15191526
/// The conversion creates an internal error variant of `RpcError`

src/generated_schema/2025_06_18/schema_utils.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,14 +1466,22 @@ impl CallToolError {
14661466
CallToolError(Box::new(UnknownTool(tool_name.into())))
14671467
}
14681468

1469-
pub fn invalid_arguments(tool_name: impl Into<String>, message: Option<impl Into<String>>) -> Self {
1470-
let tool_name = tool_name.into();
1471-
let message = message.map(|m| m.into());
1472-
1473-
let full_message = match message {
1474-
Some(msg) => format!("Invalid arguments for tool '{tool_name}': {msg}"),
1475-
None => format!("Invalid arguments for tool '{tool_name}'"),
1476-
};
1469+
/// Creates a `CallToolError` for invalid arguments with optional details.
1470+
///
1471+
pub fn invalid_arguments(tool_name: impl AsRef<str>, message: Option<String>) -> Self {
1472+
// Trim tool_name to remove whitespace and check for emptiness
1473+
let tool_name = tool_name.as_ref().trim();
1474+
if tool_name.is_empty() {
1475+
return Self::from_message("Invalid arguments: tool name cannot be empty".to_string());
1476+
}
1477+
1478+
// Use a descriptive default message if none provided
1479+
let default_message = "no additional details provided".to_string();
1480+
let message = message.unwrap_or(default_message);
1481+
1482+
// Format the full error message
1483+
let full_message = format!("Invalid arguments for tool '{tool_name}': {message}");
1484+
14771485
Self::from_message(full_message)
14781486
}
14791487

src/generated_schema/draft/schema_utils.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,22 @@ impl CallToolError {
14681468
CallToolError(Box::new(UnknownTool(tool_name.into())))
14691469
}
14701470

1471-
pub fn invalid_arguments(tool_name: impl Into<String>, message: Option<impl Into<String>>) -> Self {
1472-
let tool_name = tool_name.into();
1473-
let message = message.map(|m| m.into());
1474-
1475-
let full_message = match message {
1476-
Some(msg) => format!("Invalid arguments for tool '{tool_name}': {msg}"),
1477-
None => format!("Invalid arguments for tool '{tool_name}'"),
1478-
};
1471+
/// Creates a `CallToolError` for invalid arguments with optional details.
1472+
///
1473+
pub fn invalid_arguments(tool_name: impl AsRef<str>, message: Option<String>) -> Self {
1474+
// Trim tool_name to remove whitespace and check for emptiness
1475+
let tool_name = tool_name.as_ref().trim();
1476+
if tool_name.is_empty() {
1477+
return Self::from_message("Invalid arguments: tool name cannot be empty".to_string());
1478+
}
1479+
1480+
// Use a descriptive default message if none provided
1481+
let default_message = "no additional details provided".to_string();
1482+
let message = message.unwrap_or(default_message);
1483+
1484+
// Format the full error message
1485+
let full_message = format!("Invalid arguments for tool '{tool_name}': {message}");
1486+
14791487
Self::from_message(full_message)
14801488
}
14811489

0 commit comments

Comments
 (0)