Uh oh!
There was an error while loading. Please reload this page.
feat: add trait-based tool declaration - #677
Conversation
DaleSeo
left a comment
There was a problem hiding this comment.
Thanks for your contribution, @Evian-Zhang! This trait-based approach seems like a solid solution to a real ergonomic issue.
For a follow-up, it would be great to see some unit tests that cover both the happy path and error conversion for sync_tool_wrapper and async_tool_wrapper. The documentation tests show usage well, but having dedicated tests would give us more confidence in handling edge cases.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Evian-Zhang
commented
Feb 25, 2026
Thank you for your great suggestions! I have updated code following your advice. I have added tests for both the happy path and error conversion for |
DaleSeo
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround on the feedback, @Evian-Zhang!
Uh oh!
There was an error while loading. Please reload this page.
Motivation and Context
Current documentation recommends using
tool_routerandtoolmacros to declare tools. However, for complex business logics, each tool is often organized into separate files/modules. The macro-based approach needs to import all of tool function, tool input, and tool output types, and the name and description of such a tool cannot be put into the corresponding submodule, leading to a not-so-good encapsulation and separation.With the trait-based approach added in this PR, each tool can declare all related stuff in their own module, and the tool router only needs to import the tool struct itself, making the code organization more clear.
How Has This Been Tested?
This has been adopted in our internal mcp server as a best-practice. The doc tests added in this PR will fully cover this trait-based approach. (It is not marked with
ignore, so it will be tested in CI).Breaking Changes
No.
Types of changes
Checklist
Additional context