1717use Mcp \Capability \Registry \ResourceReference ;
1818use Mcp \Capability \Registry \ResourceTemplateReference ;
1919use Mcp \Capability \Registry \ToolReference ;
20+ use Mcp \Event \PromptListChangedEvent ;
21+ use Mcp \Event \ResourceListChangedEvent ;
22+ use Mcp \Event \ResourceTemplateListChangedEvent ;
23+ use Mcp \Event \ToolListChangedEvent ;
2024use Mcp \Schema \Prompt ;
2125use Mcp \Schema \Resource ;
2226use Mcp \Schema \ResourceTemplate ;
2327use Mcp \Schema \ServerCapabilities ;
2428use Mcp \Schema \Tool ;
29+ use Psr \EventDispatcher \EventDispatcherInterface ;
2530use Psr \Log \LoggerInterface ;
2631use Psr \Log \NullLogger ;
2732
@@ -56,6 +61,7 @@ final class Registry implements ReferenceProviderInterface, ReferenceRegistryInt
5661 private array $ resourceTemplates = [];
5762
5863 public function __construct (
64+ private readonly ?EventDispatcherInterface $ eventDispatcher = null ,
5965 private readonly LoggerInterface $ logger = new NullLogger (),
6066 ) {
6167 }
@@ -68,12 +74,12 @@ public function getCapabilities(): ServerCapabilities
6874
6975 return new ServerCapabilities (
7076 tools: [] !== $ this ->tools ,
71- toolsListChanged: false ,
77+ toolsListChanged: $ this -> eventDispatcher instanceof EventDispatcherInterface ,
7278 resources: [] !== $ this ->resources || [] !== $ this ->resourceTemplates ,
7379 resourcesSubscribe: false ,
74- resourcesListChanged: false ,
80+ resourcesListChanged: $ this -> eventDispatcher instanceof EventDispatcherInterface ,
7581 prompts: [] !== $ this ->prompts ,
76- promptsListChanged: false ,
82+ promptsListChanged: $ this -> eventDispatcher instanceof EventDispatcherInterface ,
7783 logging: false ,
7884 completions: true ,
7985 );
@@ -93,6 +99,8 @@ public function registerTool(Tool $tool, callable|array|string $handler, bool $i
9399 }
94100
95101 $ this ->tools [$ toolName ] = new ToolReference ($ tool , $ handler , $ isManual );
102+
103+ $ this ->eventDispatcher ?->dispatch(new ToolListChangedEvent ());
96104 }
97105
98106 public function registerResource (Resource $ resource , callable |array |string $ handler , bool $ isManual = false ): void
@@ -109,6 +117,8 @@ public function registerResource(Resource $resource, callable|array|string $hand
109117 }
110118
111119 $ this ->resources [$ uri ] = new ResourceReference ($ resource , $ handler , $ isManual );
120+
121+ $ this ->eventDispatcher ?->dispatch(new ResourceListChangedEvent ());
112122 }
113123
114124 public function registerResourceTemplate (
@@ -134,6 +144,8 @@ public function registerResourceTemplate(
134144 $ isManual ,
135145 $ completionProviders ,
136146 );
147+
148+ $ this ->eventDispatcher ?->dispatch(new ResourceTemplateListChangedEvent ());
137149 }
138150
139151 public function registerPrompt (
@@ -154,6 +166,8 @@ public function registerPrompt(
154166 }
155167
156168 $ this ->prompts [$ promptName ] = new PromptReference ($ prompt , $ handler , $ isManual , $ completionProviders );
169+
170+ $ this ->eventDispatcher ?->dispatch(new PromptListChangedEvent ());
157171 }
158172
159173 public function clear (): void
0 commit comments