@@ -342,6 +342,62 @@ public function testHandleWithSpecialCharactersInArguments(): void
342342 $ this ->assertEquals ($ expectedResult , $ response ->result );
343343 }
344344
345+ public function testHandleReturnsStructuredContentResult (): void
346+ {
347+ $ request = $ this ->createCallToolRequest ('structured_tool ' , ['query ' => 'php ' ]);
348+ $ toolReference = $ this ->createMock (ToolReference::class);
349+ $ structuredResult = new CallToolResult ([new TextContent ('Rendered results ' )], false , ['result ' => 'Rendered results ' ]);
350+
351+ $ this ->referenceProvider
352+ ->expects ($ this ->once ())
353+ ->method ('getTool ' )
354+ ->with ('structured_tool ' )
355+ ->willReturn ($ toolReference );
356+
357+ $ this ->referenceHandler
358+ ->expects ($ this ->once ())
359+ ->method ('handle ' )
360+ ->with ($ toolReference , ['query ' => 'php ' ])
361+ ->willReturn ($ structuredResult );
362+
363+ $ toolReference
364+ ->expects ($ this ->never ())
365+ ->method ('formatResult ' );
366+
367+ $ response = $ this ->handler ->handle ($ request , $ this ->session );
368+
369+ $ this ->assertInstanceOf (Response::class, $ response );
370+ $ this ->assertSame ($ structuredResult , $ response ->result );
371+ }
372+
373+ public function testHandleReturnsCallToolResult (): void
374+ {
375+ $ request = $ this ->createCallToolRequest ('result_tool ' , ['query ' => 'php ' ]);
376+ $ toolReference = $ this ->createMock (ToolReference::class);
377+ $ callToolResult = new CallToolResult ([new TextContent ('Error result ' )], true );
378+
379+ $ this ->referenceProvider
380+ ->expects ($ this ->once ())
381+ ->method ('getTool ' )
382+ ->with ('result_tool ' )
383+ ->willReturn ($ toolReference );
384+
385+ $ this ->referenceHandler
386+ ->expects ($ this ->once ())
387+ ->method ('handle ' )
388+ ->with ($ toolReference , ['query ' => 'php ' ])
389+ ->willReturn ($ callToolResult );
390+
391+ $ toolReference
392+ ->expects ($ this ->never ())
393+ ->method ('formatResult ' );
394+
395+ $ response = $ this ->handler ->handle ($ request , $ this ->session );
396+
397+ $ this ->assertInstanceOf (Response::class, $ response );
398+ $ this ->assertSame ($ callToolResult , $ response ->result );
399+ }
400+
345401 /**
346402 * @param array<string, mixed> $arguments
347403 */
0 commit comments