|
21 | 21 | use Mcp\Schema\JsonRpc\Response; |
22 | 22 | use Mcp\Schema\Request\CallToolRequest; |
23 | 23 | use Mcp\Schema\Result\CallToolResult; |
| 24 | +use Mcp\Schema\Result\CallToolStructuredContentResult; |
24 | 25 | use Mcp\Server\Handler\Request\CallToolHandler; |
25 | 26 | use Mcp\Server\Session\SessionInterface; |
26 | 27 | use PHPUnit\Framework\MockObject\MockObject; |
@@ -342,6 +343,63 @@ public function testHandleWithSpecialCharactersInArguments(): void |
342 | 343 | $this->assertEquals($expectedResult, $response->result); |
343 | 344 | } |
344 | 345 |
|
| 346 | + public function testHandleReturnsStructuredContentResult(): void |
| 347 | + { |
| 348 | + $request = $this->createCallToolRequest('structured_tool', ['query' => 'php']); |
| 349 | + $toolReference = $this->createMock(ToolReference::class); |
| 350 | + $innerResult = new CallToolResult([new TextContent('Rendered results')]); |
| 351 | + $structuredResult = new CallToolStructuredContentResult(['result' => 'Rendered results'], $innerResult); |
| 352 | + |
| 353 | + $this->referenceProvider |
| 354 | + ->expects($this->once()) |
| 355 | + ->method('getTool') |
| 356 | + ->with('structured_tool') |
| 357 | + ->willReturn($toolReference); |
| 358 | + |
| 359 | + $this->referenceHandler |
| 360 | + ->expects($this->once()) |
| 361 | + ->method('handle') |
| 362 | + ->with($toolReference, ['query' => 'php']) |
| 363 | + ->willReturn($structuredResult); |
| 364 | + |
| 365 | + $toolReference |
| 366 | + ->expects($this->never()) |
| 367 | + ->method('formatResult'); |
| 368 | + |
| 369 | + $response = $this->handler->handle($request, $this->session); |
| 370 | + |
| 371 | + $this->assertInstanceOf(Response::class, $response); |
| 372 | + $this->assertSame($structuredResult, $response->result); |
| 373 | + } |
| 374 | + |
| 375 | + public function testHandleReturnsCallToolResult(): void |
| 376 | + { |
| 377 | + $request = $this->createCallToolRequest('result_tool', ['query' => 'php']); |
| 378 | + $toolReference = $this->createMock(ToolReference::class); |
| 379 | + $callToolResult = new CallToolResult([new TextContent('Rendered results')]); |
| 380 | + |
| 381 | + $this->referenceProvider |
| 382 | + ->expects($this->once()) |
| 383 | + ->method('getTool') |
| 384 | + ->with('result_tool') |
| 385 | + ->willReturn($toolReference); |
| 386 | + |
| 387 | + $this->referenceHandler |
| 388 | + ->expects($this->once()) |
| 389 | + ->method('handle') |
| 390 | + ->with($toolReference, ['query' => 'php']) |
| 391 | + ->willReturn($callToolResult); |
| 392 | + |
| 393 | + $toolReference |
| 394 | + ->expects($this->never()) |
| 395 | + ->method('formatResult'); |
| 396 | + |
| 397 | + $response = $this->handler->handle($request, $this->session); |
| 398 | + |
| 399 | + $this->assertInstanceOf(Response::class, $response); |
| 400 | + $this->assertSame($callToolResult, $response->result); |
| 401 | + } |
| 402 | + |
345 | 403 | /** |
346 | 404 | * @param array<string, mixed> $arguments |
347 | 405 | */ |
|
0 commit comments