Skip to content

Commit abdd1f2

Browse files
committed
No need for extra abstractions if we are calling notifications directly
1 parent 138fea6 commit abdd1f2

File tree

6 files changed

+13
-115
lines changed

6 files changed

+13
-115
lines changed

src/Capability/Registry.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
use Mcp\Capability\Registry\ResourceReference;
1818
use Mcp\Capability\Registry\ResourceTemplateReference;
1919
use Mcp\Capability\Registry\ToolReference;
20-
use Mcp\Event\PromptListChangedEvent;
21-
use Mcp\Event\ResourceListChangedEvent;
22-
use Mcp\Event\ResourceTemplateListChangedEvent;
23-
use Mcp\Event\ToolListChangedEvent;
2420
use Mcp\Exception\InvalidArgumentException;
2521
use Mcp\Schema\Content\PromptMessage;
2622
use Mcp\Schema\Content\ResourceContents;
23+
use Mcp\Schema\Notification\PromptListChangedNotification;
24+
use Mcp\Schema\Notification\ResourceListChangedNotification;
25+
use Mcp\Schema\Notification\ToolListChangedNotification;
2726
use Mcp\Schema\Prompt;
2827
use Mcp\Schema\Resource;
2928
use Mcp\Schema\ResourceTemplate;
@@ -102,7 +101,7 @@ public function registerTool(Tool $tool, callable|array|string $handler, bool $i
102101

103102
$this->tools[$toolName] = new ToolReference($tool, $handler, $isManual);
104103

105-
$this->notificationPublisher->enqueue(new ToolListChangedEvent());
104+
$this->notificationPublisher->enqueue(ToolListChangedNotification::class);
106105
}
107106

108107
/**
@@ -121,7 +120,7 @@ public function registerResource(Resource $resource, callable|array|string $hand
121120

122121
$this->resources[$uri] = new ResourceReference($resource, $handler, $isManual);
123122

124-
$this->notificationPublisher->enqueue(new ResourceListChangedEvent());
123+
$this->notificationPublisher->enqueue(ResourceListChangedNotification::class);
125124
}
126125

127126
/**
@@ -145,7 +144,8 @@ public function registerResourceTemplate(
145144

146145
$this->resourceTemplates[$uriTemplate] = new ResourceTemplateReference($template, $handler, $isManual, $completionProviders);
147146

148-
$this->notificationPublisher->enqueue(new ResourceTemplateListChangedEvent());
147+
// TODO: Create ResourceTemplateListChangedNotification.
148+
// $this->notificationPublisher->enqueue(ResourceTemplateListChangedNotification::class);
149149
}
150150

151151
/**
@@ -169,7 +169,7 @@ public function registerPrompt(
169169

170170
$this->prompts[$promptName] = new PromptReference($prompt, $handler, $isManual, $completionProviders);
171171

172-
$this->notificationPublisher->enqueue(new PromptListChangedEvent());
172+
$this->notificationPublisher->enqueue(PromptListChangedNotification::class);
173173
}
174174

175175
/**

src/Event/PromptListChangedEvent.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Event/ResourceListChangedEvent.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Event/ResourceTemplateListChangedEvent.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Event/ToolListChangedEvent.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Server/NotificationPublisher.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,14 @@
1313

1414
namespace Mcp\Server;
1515

16-
use Mcp\Event\PromptListChangedEvent;
17-
use Mcp\Event\ResourceListChangedEvent;
18-
use Mcp\Event\ToolListChangedEvent;
1916
use Mcp\JsonRpc\MessageFactory;
2017
use Mcp\Schema\JsonRpc\Notification;
21-
use Mcp\Schema\Notification\PromptListChangedNotification;
22-
use Mcp\Schema\Notification\ResourceListChangedNotification;
23-
use Mcp\Schema\Notification\ToolListChangedNotification;
24-
use Symfony\Contracts\EventDispatcher\Event;
2518

2619
/**
2720
* @author Aggelos Bellos <aggelosbellos7@gmail.com>
2821
*/
2922
class NotificationPublisher
3023
{
31-
/**
32-
* @var array<class-string<Event>, class-string<Notification>>
33-
*/
34-
public const EVENTS_TO_NOTIFICATIONS = [
35-
ResourceListChangedEvent::class => ResourceListChangedNotification::class,
36-
PromptListChangedEvent::class => PromptListChangedNotification::class,
37-
ToolListChangedEvent::class => ToolListChangedNotification::class,
38-
];
39-
4024
/** @var list<Notification> */
4125
private array $queue = [];
4226

@@ -50,14 +34,12 @@ public static function make(): self
5034
return new self(MessageFactory::make());
5135
}
5236

53-
public function enqueue(Event $event): void
37+
/**
38+
* @param class-string<Notification> $notificationType
39+
* @return void
40+
*/
41+
public function enqueue(string $notificationType): void
5442
{
55-
$eventClass = $event::class;
56-
if (!isset(self::EVENTS_TO_NOTIFICATIONS[$eventClass])) {
57-
return;
58-
}
59-
60-
$notificationType = self::EVENTS_TO_NOTIFICATIONS[$eventClass];
6143
$notification = $this->factory->createByType($notificationType, []);
6244

6345
$this->queue[] = $notification;

0 commit comments

Comments
 (0)