File tree Expand file tree Collapse file tree 4 files changed +11
-3
lines changed Expand file tree Collapse file tree 4 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1818 public const INVALID_PARAMS = -32602 ;
1919 public const INTERNAL_ERROR = -32603 ;
2020 public const PARSE_ERROR = -32700 ;
21+ public const RESOURCE_NOT_FOUND = -32002 ;
2122
2223 public function __construct (
2324 public string |int $ id ,
Original file line number Diff line number Diff line change 1111
1212namespace Symfony \AI \McpSdk \Message ;
1313
14- final class Request implements \JsonSerializable, \Stringable
14+ final readonly class Request implements \JsonSerializable, \Stringable
1515{
1616 /**
1717 * @param array<string, mixed>|null $params
Original file line number Diff line number Diff line change @@ -89,11 +89,15 @@ public function process(string $input): iterable
8989 } catch (NotFoundExceptionInterface $ e ) {
9090 $ this ->logger ->warning (\sprintf ('Failed to create response: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
9191
92- yield $ this ->encodeResponse (Error::methodNotFound ($ message ->id ?? 0 , $ e ->getMessage ()));
92+ yield $ this ->encodeResponse (Error::methodNotFound ($ message ->id , $ e ->getMessage ()));
9393 } catch (\InvalidArgumentException $ e ) {
9494 $ this ->logger ->warning (\sprintf ('Invalid argument: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
9595
96- yield $ this ->encodeResponse (Error::invalidParams ($ message ->id ?? 0 , $ e ->getMessage ()));
96+ yield $ this ->encodeResponse (Error::invalidParams ($ message ->id , $ e ->getMessage ()));
97+ } catch (\Throwable $ e ) {
98+ $ this ->logger ->critical (\sprintf ('Uncaught exception: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
99+
100+ yield $ this ->encodeResponse (Error::internalError ($ message ->id , $ e ->getMessage ()));
97101 }
98102 }
99103 }
Original file line number Diff line number Diff line change 1414use Symfony \AI \McpSdk \Capability \Resource \ResourceRead ;
1515use Symfony \AI \McpSdk \Capability \Resource \ResourceReaderInterface ;
1616use Symfony \AI \McpSdk \Exception \ExceptionInterface ;
17+ use Symfony \AI \McpSdk \Exception \ResourceNotFoundException ;
1718use Symfony \AI \McpSdk \Message \Error ;
1819use Symfony \AI \McpSdk \Message \Request ;
1920use Symfony \AI \McpSdk \Message \Response ;
@@ -31,6 +32,8 @@ public function createResponse(Request $message): Response|Error
3132
3233 try {
3334 $ result = $ this ->reader ->read (new ResourceRead (uniqid ('' , true ), $ uri ));
35+ } catch (ResourceNotFoundException $ e ) {
36+ return new Error ($ message ->id , Error::RESOURCE_NOT_FOUND , $ e ->getMessage ());
3437 } catch (ExceptionInterface ) {
3538 return Error::internalError ($ message ->id , 'Error while reading resource ' );
3639 }
You can’t perform that action at this time.
0 commit comments