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 18
18
public const INVALID_PARAMS = -32602 ;
19
19
public const INTERNAL_ERROR = -32603 ;
20
20
public const PARSE_ERROR = -32700 ;
21
+ public const RESOURCE_NOT_FOUND = -32002 ;
21
22
22
23
public function __construct (
23
24
public string |int $ id ,
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \AI \McpSdk \Message ;
13
13
14
- final class Request implements \JsonSerializable, \Stringable
14
+ final readonly class Request implements \JsonSerializable, \Stringable
15
15
{
16
16
/**
17
17
* @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
89
89
} catch (NotFoundExceptionInterface $ e ) {
90
90
$ this ->logger ->warning (\sprintf ('Failed to create response: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
91
91
92
- yield $ this ->encodeResponse (Error::methodNotFound ($ message ->id ?? 0 , $ e ->getMessage ()));
92
+ yield $ this ->encodeResponse (Error::methodNotFound ($ message ->id , $ e ->getMessage ()));
93
93
} catch (\InvalidArgumentException $ e ) {
94
94
$ this ->logger ->warning (\sprintf ('Invalid argument: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
95
95
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 ()));
97
101
}
98
102
}
99
103
}
Original file line number Diff line number Diff line change 14
14
use Symfony \AI \McpSdk \Capability \Resource \ResourceRead ;
15
15
use Symfony \AI \McpSdk \Capability \Resource \ResourceReaderInterface ;
16
16
use Symfony \AI \McpSdk \Exception \ExceptionInterface ;
17
+ use Symfony \AI \McpSdk \Exception \ResourceNotFoundException ;
17
18
use Symfony \AI \McpSdk \Message \Error ;
18
19
use Symfony \AI \McpSdk \Message \Request ;
19
20
use Symfony \AI \McpSdk \Message \Response ;
@@ -31,6 +32,8 @@ public function createResponse(Request $message): Response|Error
31
32
32
33
try {
33
34
$ 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 ());
34
37
} catch (ExceptionInterface ) {
35
38
return Error::internalError ($ message ->id , 'Error while reading resource ' );
36
39
}
You can’t perform that action at this time.
0 commit comments