@@ -4,7 +4,7 @@ use proc_macro2::TokenStream;
44use quote:: { ToTokens , quote} ;
55use syn:: {
66 Expr , FnArg , Ident , ItemFn , ItemImpl , MetaList , PatType , Token , Type , Visibility , parse:: Parse ,
7- parse_quote,
7+ parse_quote, spanned :: Spanned ,
88} ;
99
1010#[ derive( Default ) ]
@@ -21,6 +21,7 @@ impl Parse for ToolImplItemAttrs {
2121 "tool_box" => {
2222 tool_box = Some ( None ) ;
2323 if input. lookahead1 ( ) . peek ( Token ! [ =] ) {
24+ input. parse :: < Token ! [ =] > ( ) ?;
2425 let value: Ident = input. parse ( ) ?;
2526 tool_box = Some ( Some ( value) ) ;
2627 }
@@ -224,6 +225,11 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
224225 rmcp:: tool_box!( @derive #ident) ;
225226 ) ) ;
226227 }
228+ } else {
229+ return Err ( syn:: Error :: new (
230+ proc_macro2:: Span :: call_site ( ) ,
231+ "tool_box attribute is required for trait implementation" ,
232+ ) ) ;
227233 }
228234 } else if let Some ( ident) = tool_box_ident {
229235 // if it is a normal impl block
@@ -367,6 +373,12 @@ pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Resu
367373 unextractable_args_indexes. insert ( index) ;
368374 }
369375 Some ( Caught :: Aggregated ( rust_type) ) => {
376+ if let ToolParams :: Params { .. } = tool_macro_attrs. params {
377+ return Err ( syn:: Error :: new (
378+ rust_type. span ( ) ,
379+ "cannot mix aggregated and individual parameters" ,
380+ ) ) ;
381+ }
370382 tool_macro_attrs. params = ToolParams :: Aggregated { rust_type } ;
371383 unextractable_args_indexes. insert ( index) ;
372384 }
@@ -626,10 +638,12 @@ mod test {
626638
627639 #[ test]
628640 fn test_trait_tool_macro ( ) -> syn:: Result < ( ) > {
629- let attr = quote ! { } ;
641+ let attr = quote ! {
642+ tool_box = Calculator
643+ } ;
630644 let input = quote ! {
631645 impl ServerHandler for Calculator {
632- tool_box! ( @derive ) ;
646+ # [ tool ]
633647 fn get_info( & self ) -> ServerInfo {
634648 ServerInfo {
635649 instructions: Some ( "A simple calculator" . into( ) ) ,
0 commit comments