Open
Description
I think some parts are a bit redundant, such as having to mark each variable with #[tool(param)] or #[tool(aggr)]. I looked at the source code of rcmp-macros, and I think we can simply judge by the number of variables after excluding variables such as self. When it is greater than 1, pack them together, and use a single one in other cases. The effect is as follows:
use rmcp::{
ServerHandler,
handler::server::wrapper::Json,
model::{ServerCapabilities, ServerInfo},
schemars, tool,
};
use serde::Serialize;
#[derive(Debug,Serialize, serde::Deserialize, schemars::JsonSchema)]
pub struct SumRequest {
#[schemars(description = "the left hand side number")]
pub a: i32,
pub b: i32,
}
#[derive(Debug, Clone)]
pub struct Calculator;
#[tool(tool_box)]
impl Calculator {
#[tool(description = "Calculate the sum of two numbers")]
fn sum(&self, sum: SumRequest) -> String {
(sum.a+sum.b).to_string()
}
#[tool(description = "Calculate the difference of two numbers")]
fn sub(
&self,
a: i32,
b: i32,
) -> Json<i32> {
Json(a - b)
}
}