Issue Description
Currently, tool functions can only return String directly or implement the IntoCallToolResult trait for custom types. This limits the flexibility and requires unnecessary boilerplate.
Suggested Enhancement
Allow tool functions to return any serializable type by:
- Making
#[tool(param)] attribute optional on function parameters
- Automatically converting return values to
CallToolResult using serde serialization
Benefits
- Easier function definitions
- Cleaner test code
- More intuitive API
- Less boilerplate implementation
- Better type safety
Example (Current vs Proposed)
Current approach:
#[tool(description = "Calculate sum")]
fn sum(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
(a + b).to_string()
}
Proposed approach:
#[tool(description = "Calculate sum")]
fn sum(&self, a: i32, b: i32) -> i32 {
a + b
}
This enhancement would make the API more ergonomic while maintaining all current functionality.
Issue Description
Currently, tool functions can only return
Stringdirectly or implement theIntoCallToolResulttrait for custom types. This limits the flexibility and requires unnecessary boilerplate.Suggested Enhancement
Allow tool functions to return any serializable type by:
#[tool(param)]attribute optional on function parametersCallToolResultusing serde serializationBenefits
Example (Current vs Proposed)
Current approach:
Proposed approach:
This enhancement would make the API more ergonomic while maintaining all current functionality.