@@ -313,7 +313,7 @@ pub fn dispatch_tool_command(
313313 let input_str = args
314314 . get ( "input" )
315315 . and_then ( Value :: as_str)
316- . ok_or_else ( || AppError :: General ( "Missing required argument: ' input'" . into ( ) ) ) ?;
316+ . ok_or ( AppError :: MissingArgument { argument : " input" } ) ?;
317317 let output_str = args
318318 . get ( "output" )
319319 . and_then ( Value :: as_str)
@@ -336,7 +336,7 @@ pub fn dispatch_tool_command(
336336 let input_str = args
337337 . get ( "input" )
338338 . and_then ( Value :: as_str)
339- . ok_or_else ( || AppError :: General ( "Missing required argument: ' input'" . into ( ) ) ) ?;
339+ . ok_or ( AppError :: MissingArgument { argument : " input" } ) ?;
340340 let no_imports = args
341341 . get ( "no_imports" )
342342 . and_then ( Value :: as_bool)
@@ -377,7 +377,7 @@ pub fn dispatch_tool_command(
377377 . get ( "dir" )
378378 . or_else ( || args. get ( "input" ) )
379379 . and_then ( Value :: as_str)
380- . ok_or_else ( || AppError :: General ( "Missing required argument: ' dir'" . into ( ) ) ) ?;
380+ . ok_or ( AppError :: MissingArgument { argument : " dir" } ) ?;
381381 let truth_str = args. get ( "truth" ) . and_then ( Value :: as_str) . unwrap_or ( "code" ) ;
382382 let output_str = args
383383 . get ( "output" )
@@ -446,7 +446,7 @@ pub fn dispatch_tool_command(
446446 let input_str = args
447447 . get ( "input" )
448448 . and_then ( Value :: as_str)
449- . ok_or_else ( || AppError :: General ( "Missing required argument: ' input'" . into ( ) ) ) ?;
449+ . ok_or ( AppError :: MissingArgument { argument : " input" } ) ?;
450450 let output_str = args
451451 . get ( "output" )
452452 . and_then ( Value :: as_str)
@@ -473,7 +473,9 @@ pub fn dispatch_tool_command(
473473 output_str
474474 ) )
475475 }
476- _ => Err ( AppError :: General ( format ! ( "Tool not found: {}" , tool_name) ) ) ,
476+ _ => Err ( AppError :: ToolNotFound {
477+ tool : tool_name. to_string ( ) ,
478+ } ) ,
477479 }
478480}
479481
@@ -583,23 +585,18 @@ pub fn handle_request(input: &str) -> Option<String> {
583585 } ;
584586 ok_response ( req. id , & result)
585587 }
588+ Err ( e @ AppError :: ToolNotFound { .. } ) => {
589+ err_response ( req. id , -32601 , e. to_string ( ) )
590+ }
586591 Err ( e) => {
587- if call_params. name != "from_openapi"
588- && call_params. name != "to_openapi"
589- && call_params. name != "to_docs_json"
590- && call_params. name != "sync"
591- {
592- err_response ( req. id , -32601 , e. to_string ( ) )
593- } else {
594- let result = CallToolResult {
595- content : vec ! [ CallToolResultContent :: Text ( TextContent {
596- text: format!( "Error executing {}: {}" , call_params. name, e) ,
597- } ) ] ,
598- is_error : Some ( true ) ,
599- meta : None ,
600- } ;
601- ok_response ( req. id , & result)
602- }
592+ let result = CallToolResult {
593+ content : vec ! [ CallToolResultContent :: Text ( TextContent {
594+ text: format!( "Error executing {}: {}" , call_params. name, e) ,
595+ } ) ] ,
596+ is_error : Some ( true ) ,
597+ meta : None ,
598+ } ;
599+ ok_response ( req. id , & result)
603600 }
604601 }
605602 }
0 commit comments