@@ -175,6 +175,38 @@ public function testCallThrowsToolNotFoundExceptionWhenToolNotFound(): void
175175 $ this ->toolCaller ->call ($ request );
176176 }
177177
178+ public function testCallThrowsToolExecutionException (): void
179+ {
180+ $ request = new CallToolRequest ('test_tool ' , ['param ' => 'value ' ]);
181+ $ tool = $ this ->createValidTool ('test_tool ' );
182+ $ exception = new class extends \Exception implements \Mcp \Exception \ToolExecutionExceptionInterface {
183+ public function getErrorMessages (): array
184+ {
185+ return ['test error ' ];
186+ }
187+ };
188+ $ toolReference = new ToolReference ($ tool , fn () => throw $ exception );
189+
190+ $ this ->referenceProvider
191+ ->expects ($ this ->once ())
192+ ->method ('getTool ' )
193+ ->with ('test_tool ' )
194+ ->willReturn ($ toolReference );
195+
196+ $ this ->referenceHandler
197+ ->expects ($ this ->once ())
198+ ->method ('handle ' )
199+ ->with ($ toolReference , ['param ' => 'value ' ])
200+ ->willThrowException ($ exception );
201+
202+ $ result = $ this ->toolCaller ->call ($ request );
203+
204+ $ this ->assertCount (1 , $ result ->content );
205+ $ this ->assertInstanceOf (TextContent::class, $ result ->content [0 ]);
206+ $ this ->assertEquals ('test error ' , $ result ->content [0 ]->text );
207+ $ this ->assertTrue ($ result ->isError );
208+ }
209+
178210 public function testCallThrowsToolExecutionExceptionWhenHandlerThrowsException (): void
179211 {
180212 $ request = new CallToolRequest ('failing_tool ' , ['param ' => 'value ' ]);
0 commit comments