-
Notifications
You must be signed in to change notification settings - Fork 158
Enhance Tool Macro Functionality #161
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
base: main
Are you sure you want to change the base?
Conversation
Apart from your functional changes, I want to point out follows:
|
Got it. As for the problem of comment names, it is related to my git config configuration. I have always been working on personal projects and trying to submit PR for the first time, so I don't have enough experience in these. Some insignificant changes are related to my use of cargo clippy --fix after deleting rustfmt. Some things may have been changed by clippy (guessing) |
@yIllusionSky Yeah, It's your freedom to leave your real name in commit message, just a reminder since I can tell that you don't often commit to public project. And we may need a clippy config @jokemanfire. It would be another pr. |
## Changes Simplified the usage of rcmp-macros with the following changes: ### Before ```rust #[tool(tool_box)] impl Calculator { #[tool(description = "Calculate the sum of two numbers")] fn sum(&self, #[tool(aggr)] SumRequest { a, b }: SumRequest) -> String { (a + b).to_string() } #[tool(description = "Calculate the difference of two numbers")] fn sub( &self, #[tool(param)] #[schemars(description = "the left hand side number")] a: i32, #[tool(param)] #[schemars(description = "the right hand side number")] b: i32, ) -> Json<i32> { Json(a - b) } } ``` ### After ```rust #[tool(tool_box)] impl Calculator { #[tool(description = "Calculate the sum of two numbers",aggr)] fn sum(&self, SumRequest { a, b }: SumRequest) -> String { (a + b).to_string() } #[tool(description = "Calculate the difference of two numbers")] fn sub( &self, #[schemars(description = "the left hand side number")] a: i32, #[schemars(description = "the right hand side number")] b: i32, ) -> Json<i32> { Json(a - b) } } ``` ## Improvements 1. Moved parameter-level `#[tool(aggr)]` attribute to the function level 2. Removed redundant `#[tool(param)]` markers 3. Maintained the same functionality while making the code more concise and readable
## Changes This modification simplifies the usage of rmcp-macros, with the following key changes: ### 1. Merged Toolbox Declaration and Description **Reference Example:** Original code: ```rust #[tool(tool_box)] impl Calculator { // Tool method implementations } #[tool(tool_box)] impl ServerHandler for Calculator { fn get_info(&self) -> ServerInfo { ServerInfo { instructions: Some("A simple calculator".into()), capabilities: ServerCapabilities::builder().enable_tools().build(), ..Default::default() } } } ``` Simplified: ```rust #[tool(tool_box,description = "A simple calculator")] impl Calculator { // Tool method implementations } ``` ### 2. Simplified Implementation Process - No longer requires separate implementation of the `ServerHandler` trait - Tool descriptions are provided directly through macro parameters - Reduces redundant code, improving maintainability ## Advantages 1. More concise code 2. Reduced boilerplate 3. More intuitive API usage 4. Lower barrier to entry
I reconstructed a new one according to the idea I gave you, except for a few differences in the naming. |
right, I am interested in this submit and I will also take a look later. |
I tried to fix the cli's warn error.
These rustfmt configurations require unstable configuration to start, but rust-toolchain does not configure unstable |
you may forget update the stable channel in rustc. :) |
I have been developing with the latest nightly version of rust, and I update rustup almost every week.I think that might not be the problem? |
Changes
rust-toolchain.toml
file as project doesn't need to restrict to a specific Rust version#[tool(param)]
and#[tool(aggr)]
parameters without manual markingtool_impl_item
functionality for default implementation ofServerHandler
traitdefault_build
parameter (defaults to true, can be disabled withdefault_build=false
)Benefits
These improvements simplify API usage and reduce manual configuration needs. In most cases, users only need to mark
#[tool(tool_box)]
to get default implementation of theServerHandler
trait.Testing
Basic tests have been performed to verify functionality.