Skip to content

Proposal: Allow any return type in tool functions #75

@cpunion

Description

@cpunion

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:

  1. Making #[tool(param)] attribute optional on function parameters
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions