|
13 | 13 |
|
14 | 14 | use Mcp\Capability\Prompt\Completion\EnumCompletionProvider; |
15 | 15 | use Mcp\Capability\Registry; |
| 16 | +use Mcp\Schema\Notification\PromptListChangedNotification; |
| 17 | +use Mcp\Schema\Notification\ResourceListChangedNotification; |
| 18 | +use Mcp\Schema\Notification\ToolListChangedNotification; |
16 | 19 | use Mcp\Schema\Prompt; |
17 | 20 | use Mcp\Schema\Resource; |
18 | 21 | use Mcp\Schema\ResourceTemplate; |
@@ -305,6 +308,57 @@ public function testMultipleRegistrationsOfSameElementWithSameType(): void |
305 | 308 | $this->assertEquals('second', ($toolRef->handler)()); |
306 | 309 | } |
307 | 310 |
|
| 311 | + public function testToolRegistrationTriggersNotification(): void |
| 312 | + { |
| 313 | + $tool = $this->createValidTool('the-best-tool-name-ever'); |
| 314 | + |
| 315 | + $expected = [$tool->name => $tool]; |
| 316 | + |
| 317 | + $notificationPublisher = $this->createMock(NotificationPublisher::class); |
| 318 | + $notificationPublisher->expects($this->once()) |
| 319 | + ->method('enqueue') |
| 320 | + ->with(new ToolListChangedNotification()); |
| 321 | + |
| 322 | + $registry = new Registry($notificationPublisher); |
| 323 | + $registry->registerTool($tool, fn () => null); |
| 324 | + |
| 325 | + $this->assertSame($expected, $registry->getTools()); |
| 326 | + } |
| 327 | + |
| 328 | + public function testResourceRegistrationTriggersNotification(): void |
| 329 | + { |
| 330 | + $resource = $this->createValidResource('config://the-best-resource-uri-ever'); |
| 331 | + |
| 332 | + $expected = [$resource->uri => $resource]; |
| 333 | + |
| 334 | + $notificationPublisher = $this->createMock(NotificationPublisher::class); |
| 335 | + $notificationPublisher->expects($this->once()) |
| 336 | + ->method('enqueue') |
| 337 | + ->with(new ResourceListChangedNotification()); |
| 338 | + |
| 339 | + $registry = new Registry($notificationPublisher); |
| 340 | + $registry->registerResource($resource, fn () => null); |
| 341 | + |
| 342 | + $this->assertSame($expected, $registry->getResources()); |
| 343 | + } |
| 344 | + |
| 345 | + public function testPromptRegistrationTriggersNotification(): void |
| 346 | + { |
| 347 | + $prompt = $this->createValidPrompt('the-best-prompt-ever'); |
| 348 | + |
| 349 | + $expected = [$prompt->name => $prompt]; |
| 350 | + |
| 351 | + $notificationPublisher = $this->createMock(NotificationPublisher::class); |
| 352 | + $notificationPublisher->expects($this->once()) |
| 353 | + ->method('enqueue') |
| 354 | + ->with(new PromptListChangedNotification()); |
| 355 | + |
| 356 | + $registry = new Registry($notificationPublisher); |
| 357 | + $registry->registerPrompt($prompt, fn () => null); |
| 358 | + |
| 359 | + $this->assertSame($expected, $registry->getPrompts()); |
| 360 | + } |
| 361 | + |
308 | 362 | private function createValidTool(string $name): Tool |
309 | 363 | { |
310 | 364 | return new Tool( |
|
0 commit comments