1414use Psr \Log \LoggerInterface ;
1515use Symfony \AI \McpSdk \Exception \HandlerNotFoundException ;
1616use Symfony \AI \McpSdk \Exception \NotFoundExceptionInterface ;
17+ use Symfony \AI \McpSdk \Exception \ResourceNotFoundException ;
1718use Symfony \AI \McpSdk \Message \Error ;
1819use Symfony \AI \McpSdk \Message \Factory ;
1920use Symfony \AI \McpSdk \Message \Notification ;
@@ -77,6 +78,10 @@ public function process(string $message): ?string
7778 : $ this ->encodeResponse ($ this ->handleRequest ($ message ));
7879 } catch (\DomainException ) {
7980 return null ;
81+ } catch (ResourceNotFoundException $ e ) {
82+ $ this ->logger ->warning (\sprintf ('Failed to find resource: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
83+
84+ return $ this ->encodeResponse (new Error ($ message ->id ?? 0 , Error::RESOURCE_NOT_FOUND , $ e ->getMessage ()));
8085 } catch (NotFoundExceptionInterface $ e ) {
8186 $ this ->logger ->warning (\sprintf ('Failed to create response: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
8287
@@ -85,6 +90,10 @@ public function process(string $message): ?string
8590 $ this ->logger ->warning (\sprintf ('Invalid argument: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
8691
8792 return $ this ->encodeResponse (Error::invalidParams ($ message ->id ?? 0 , $ e ->getMessage ()));
93+ } catch (\Throwable $ e ) {
94+ $ this ->logger ->critical (\sprintf ('Uncaught exception: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
95+
96+ return $ this ->encodeResponse (Error::internalError ($ message ->id ?? 0 , $ e ->getMessage ()));
8897 }
8998 }
9099
0 commit comments