-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Allow any return type in tool functions #75
Comments
Comparison with Python SDKThe Python SDK already supports this pattern with a cleaner API: @mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
async def main():
print(add(1, 2)) # Normal function call: 3
print(await mcp.call_tool("add", {"a": 1, "b": 2})) # Via MCP: 3
if __name__ == "__main__":
asyncio.run(main()) This demonstrates how returning native types directly makes the API more intuitive. |
We can add a auto serialization wrapper to tell sdk using a JSON serialization policy, it could be looks like this. #[tool(description = "Calculate sum")]
fn sum(&self, a: i32, b: i32) -> Json<i32> {
Json(a + b)
} |
@4t145 Thanks! The Json wrapper approach looks great. |
4t145
added a commit
to 4t145/rust-sdk
that referenced
this issue
Apr 1, 2025
9 tasks
4t145
added a commit
to 4t145/rust-sdk
that referenced
this issue
Apr 1, 2025
4t145
added a commit
that referenced
this issue
Apr 1, 2025
Supported in #78 |
Great! Thank. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue Description
Currently, tool functions can only return
String
directly or implement theIntoCallToolResult
trait 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 parametersCallToolResult
using serde serializationBenefits
Example (Current vs Proposed)
Current approach:
Proposed approach:
This enhancement would make the API more ergonomic while maintaining all current functionality.
The text was updated successfully, but these errors were encountered: