@@ -72,26 +72,16 @@ pub fn expand_tool_router(args: TokenStream, mut input: ItemImpl) -> syn::Result
7272 // Generate handle_tool method
7373 let handle_tool_method = generate_handle_tool_method ( & tool_methods, & vis) ;
7474
75- // Generate router initialization method
76- let router_init = generate_router_init ( & router_field, & vis) ;
77-
7875 // Add generated methods to the impl block
76+ // Note: init_tool_router is not generated as the router field management is left to the user
7977 input. items . push ( ImplItem :: Fn ( tools_method) ) ;
8078 input. items . push ( ImplItem :: Fn ( handle_tool_method) ) ;
81- input. items . push ( ImplItem :: Fn ( router_init) ) ;
8279
8380 // Add router field to the struct (this would need to be done separately)
8481 // For now, we'll document that the user needs to add it manually
8582
86- let expanded = quote ! {
87- #input
88-
89- impl ToolRouterInfo for Self {
90- const ROUTER_FIELD : & ' static str = stringify!( #router_field) ;
91- }
92- } ;
93-
94- Ok ( expanded)
83+ // Just output the modified impl block with the generated methods
84+ Ok ( quote ! { #input } )
9585}
9686
9787/// Collect all methods marked with #[tool] from the impl block
@@ -173,21 +163,21 @@ fn generate_tools_method(methods: &[ToolMethod], vis: &Visibility) -> ImplItemFn
173163 let name = & method. tool_name ;
174164 let description = & method. description ;
175165 quote ! {
176- pmcp:: types:: Tool {
177- name : #name. to_string ( ) ,
178- description : Some ( #description. to_string( ) ) ,
179- input_schema : Some ( serde_json:: json!( {
166+ pmcp:: types:: ToolInfo :: new (
167+ #name,
168+ Some ( #description. to_string( ) ) ,
169+ serde_json:: json!( {
180170 "type" : "object" ,
181171 "properties" : { } ,
182172 "required" : [ ]
183- } ) ) ,
184- }
173+ } ) ,
174+ )
185175 }
186176 } )
187177 . collect ( ) ;
188178
189179 parse_quote ! {
190- #vis fn tools( & self ) -> Vec <pmcp:: types:: Tool > {
180+ #vis fn tools( & self ) -> Vec <pmcp:: types:: ToolInfo > {
191181 vec![
192182 #( #tool_definitions) , *
193183 ]
@@ -213,7 +203,7 @@ fn generate_handle_tool_method(methods: &[ToolMethod], vis: &Visibility) -> Impl
213203 let result = self . #method_name( args. clone( ) ) #await_token;
214204 match result {
215205 Ok ( value) => Ok ( serde_json:: to_value( value) ?) ,
216- Err ( e) => Err ( pmcp:: Error :: ToolError ( e . to_string ( ) ) ) ,
206+ Err ( e) => Err ( pmcp:: Error :: internal ( format! ( "Tool error: {}" , e ) ) ) ,
217207 }
218208 }
219209 }
@@ -225,27 +215,16 @@ fn generate_handle_tool_method(methods: &[ToolMethod], vis: &Visibility) -> Impl
225215 & self ,
226216 name: & str ,
227217 args: serde_json:: Value ,
228- extra : pmcp:: RequestHandlerExtra ,
218+ _extra : pmcp:: RequestHandlerExtra ,
229219 ) -> pmcp:: Result <serde_json:: Value > {
230220 match name {
231221 #( #match_arms) *
232- _ => Err ( pmcp:: Error :: MethodNotFound ( format!( "Unknown tool: {}" , name) ) ) ,
222+ _ => Err ( pmcp:: Error :: method_not_found ( format!( "Unknown tool: {}" , name) ) ) ,
233223 }
234224 }
235225 }
236226}
237227
238- /// Generate router initialization method
239- fn generate_router_init ( router_field : & Ident , vis : & Visibility ) -> ImplItemFn {
240- parse_quote ! {
241- #vis fn init_tool_router( & mut self ) {
242- // Initialize the tool router
243- // This is a placeholder - actual implementation would depend on the router type
244- self . #router_field = Default :: default ( ) ;
245- }
246- }
247- }
248-
249228/// Parse visibility string into syn::Visibility
250229fn parse_visibility ( vis_str : & Option < String > ) -> syn:: Result < Visibility > {
251230 match vis_str {
@@ -261,11 +240,6 @@ fn parse_visibility(vis_str: &Option<String>) -> syn::Result<Visibility> {
261240 }
262241}
263242
264- /// Trait to mark types that have a tool router
265- trait ToolRouterInfo {
266- const ROUTER_FIELD : & ' static str ;
267- }
268-
269243#[ cfg( test) ]
270244mod tests {
271245 use super :: * ;
0 commit comments