@@ -4,7 +4,7 @@ use proc_macro2::TokenStream;
4
4
use quote:: { ToTokens , quote} ;
5
5
use syn:: {
6
6
Expr , FnArg , Ident , ItemFn , ItemImpl , MetaList , PatType , Token , Type , Visibility , parse:: Parse ,
7
- parse_quote,
7
+ parse_quote, spanned :: Spanned ,
8
8
} ;
9
9
10
10
#[ derive( Default ) ]
@@ -21,6 +21,7 @@ impl Parse for ToolImplItemAttrs {
21
21
"tool_box" => {
22
22
tool_box = Some ( None ) ;
23
23
if input. lookahead1 ( ) . peek ( Token ! [ =] ) {
24
+ input. parse :: < Token ! [ =] > ( ) ?;
24
25
let value: Ident = input. parse ( ) ?;
25
26
tool_box = Some ( Some ( value) ) ;
26
27
}
@@ -224,6 +225,11 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
224
225
rmcp:: tool_box!( @derive #ident) ;
225
226
) ) ;
226
227
}
228
+ } else {
229
+ return Err ( syn:: Error :: new (
230
+ proc_macro2:: Span :: call_site ( ) ,
231
+ "tool_box attribute is required for trait implementation" ,
232
+ ) ) ;
227
233
}
228
234
} else if let Some ( ident) = tool_box_ident {
229
235
// 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
367
373
unextractable_args_indexes. insert ( index) ;
368
374
}
369
375
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
+ }
370
382
tool_macro_attrs. params = ToolParams :: Aggregated { rust_type } ;
371
383
unextractable_args_indexes. insert ( index) ;
372
384
}
@@ -626,10 +638,12 @@ mod test {
626
638
627
639
#[ test]
628
640
fn test_trait_tool_macro ( ) -> syn:: Result < ( ) > {
629
- let attr = quote ! { } ;
641
+ let attr = quote ! {
642
+ tool_box = Calculator
643
+ } ;
630
644
let input = quote ! {
631
645
impl ServerHandler for Calculator {
632
- tool_box! ( @derive ) ;
646
+ # [ tool ]
633
647
fn get_info( & self ) -> ServerInfo {
634
648
ServerInfo {
635
649
instructions: Some ( "A simple calculator" . into( ) ) ,
0 commit comments