@@ -342,6 +342,64 @@ 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+         $ this  ->assertEquals (['result '  => 'Rendered results ' ], $ response ->result ->jsonSerialize ()['structuredContent ' ] ?? []);
372+     }
373+ 
374+     public  function  testHandleReturnsCallToolResult (): void 
375+     {
376+         $ request  = $ this  ->createCallToolRequest ('result_tool ' , ['query '  => 'php ' ]);
377+         $ toolReference  = $ this  ->createMock (ToolReference::class);
378+         $ callToolResult  = new  CallToolResult ([new  TextContent ('Error result ' )], true );
379+ 
380+         $ this  ->referenceProvider 
381+             ->expects ($ this  ->once ())
382+             ->method ('getTool ' )
383+             ->with ('result_tool ' )
384+             ->willReturn ($ toolReference );
385+ 
386+         $ this  ->referenceHandler 
387+             ->expects ($ this  ->once ())
388+             ->method ('handle ' )
389+             ->with ($ toolReference , ['query '  => 'php ' ])
390+             ->willReturn ($ callToolResult );
391+ 
392+         $ toolReference
393+             ->expects ($ this  ->never ())
394+             ->method ('formatResult ' );
395+ 
396+         $ response  = $ this  ->handler ->handle ($ request , $ this  ->session );
397+ 
398+         $ this  ->assertInstanceOf (Response::class, $ response );
399+         $ this  ->assertSame ($ callToolResult , $ response ->result );
400+         $ this  ->assertArrayNotHasKey ('structuredContent ' , $ response ->result ->jsonSerialize ());
401+     }
402+ 
345403    /** 
346404     * @param array<string, mixed> $arguments 
347405     */ 
0 commit comments