Skip to content

Commit 8f46200

Browse files
committed
fix(macros): add error deal
1.Check whether the parameters include aggregated parameters and individual parameters 2.Check if the toolbox attribute is default Signed-off-by: jokemanfire <[email protected]>
1 parent 6a42304 commit 8f46200

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/rmcp-macros/src/tool.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::collections::HashSet;
33
use proc_macro2::TokenStream;
44
use quote::{ToTokens, quote};
55
use syn::{
6-
Expr, FnArg, Ident, ItemFn, ItemImpl, MetaList, PatType, Token, Type, Visibility, parse::Parse,
7-
parse_quote,
6+
parse::Parse, parse_quote, spanned::Spanned, Expr, FnArg, Ident, ItemFn, ItemImpl, MetaList, PatType, Token, Type, Visibility
87
};
98

109
#[derive(Default)]
@@ -224,6 +223,11 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
224223
rmcp::tool_box!(@derive #ident);
225224
));
226225
}
226+
} else {
227+
return Err(syn::Error::new(
228+
proc_macro2::Span::call_site(),
229+
"tool_box attribute is required for trait implementation",
230+
));
227231
}
228232
} else if let Some(ident) = tool_box_ident {
229233
// if it is a normal impl block
@@ -367,6 +371,12 @@ pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Resu
367371
unextractable_args_indexes.insert(index);
368372
}
369373
Some(Caught::Aggregated(rust_type)) => {
374+
if let ToolParams::Params { .. } = tool_macro_attrs.params {
375+
return Err(syn::Error::new(
376+
rust_type.span(),
377+
"cannot mix aggregated and individual parameters",
378+
));
379+
}
370380
tool_macro_attrs.params = ToolParams::Aggregated { rust_type };
371381
unextractable_args_indexes.insert(index);
372382
}

0 commit comments

Comments
 (0)