1212namespace Symfony \AI \McpBundle \Tests \DependencyInjection ;
1313
1414use Mcp \Capability \Registry \Loader \LoaderInterface ;
15+ use Mcp \Server \Handler \Notification \NotificationHandlerInterface ;
16+ use Mcp \Server \Handler \Request \RequestHandlerInterface ;
1517use PHPUnit \Framework \Attributes \DataProvider ;
1618use PHPUnit \Framework \TestCase ;
1719use Symfony \AI \McpBundle \McpBundle ;
20+ use Symfony \Component \DependencyInjection \Argument \TaggedIteratorArgument ;
1821use Symfony \Component \DependencyInjection \ContainerBuilder ;
1922
2023class McpBundleTest extends TestCase
@@ -149,6 +152,7 @@ public function testServerServices()
149152 $ builderDefinition = $ container ->getDefinition ('mcp.server.builder ' );
150153 $ methodCalls = $ builderDefinition ->getMethodCalls ();
151154
155+ // Check for setEventDispatcher method call
152156 $ hasEventDispatcherCall = false ;
153157 foreach ($ methodCalls as $ call ) {
154158 if ('setEventDispatcher ' === $ call [0 ]) {
@@ -157,6 +161,54 @@ public function testServerServices()
157161 }
158162 }
159163 $ this ->assertTrue ($ hasEventDispatcherCall , 'ServerBuilder should have setEventDispatcher method call ' );
164+
165+ // Check for addRequestHandlers with proper tag
166+ $ hasRequestHandlers = false ;
167+ foreach ($ methodCalls as $ call ) {
168+ if ('addRequestHandlers ' === $ call [0 ]) {
169+ $ argument = $ call [1 ][0 ];
170+ if (
171+ $ argument instanceof TaggedIteratorArgument
172+ && 'mcp.request_handler ' === $ argument ->getTag ()
173+ ) {
174+ $ hasRequestHandlers = true ;
175+ break ;
176+ }
177+ }
178+ }
179+ $ this ->assertTrue ($ hasRequestHandlers , 'ServerBuilder should have addRequestHandlers with mcp.request_handler tag ' );
180+
181+ // Check for addNotificationHandlers with proper tag
182+ $ hasNotificationHandlers = false ;
183+ foreach ($ methodCalls as $ call ) {
184+ if ('addNotificationHandlers ' === $ call [0 ]) {
185+ $ argument = $ call [1 ][0 ];
186+ if (
187+ $ argument instanceof TaggedIteratorArgument
188+ && 'mcp.notification_handler ' === $ argument ->getTag ()
189+ ) {
190+ $ hasNotificationHandlers = true ;
191+ break ;
192+ }
193+ }
194+ }
195+ $ this ->assertTrue ($ hasNotificationHandlers , 'ServerBuilder should have addNotificationHandlers with mcp.notification_handler tag ' );
196+
197+ // Check for addLoaders with proper tag
198+ $ hasLoaders = false ;
199+ foreach ($ methodCalls as $ call ) {
200+ if ('addLoaders ' === $ call [0 ]) {
201+ $ argument = $ call [1 ][0 ];
202+ if (
203+ $ argument instanceof \Symfony \Component \DependencyInjection \Argument \TaggedIteratorArgument
204+ && 'mcp.loader ' === $ argument ->getTag ()
205+ ) {
206+ $ hasLoaders = true ;
207+ break ;
208+ }
209+ }
210+ }
211+ $ this ->assertTrue ($ hasLoaders , 'ServerBuilder should have addLoaders with mcp.loader tag ' );
160212 }
161213
162214 public function testMcpToolAttributeAutoconfiguration ()
@@ -359,6 +411,24 @@ public function testLoaderInterfaceAutoconfiguration()
359411 $ this ->assertTrue ($ definition ->hasTag ('mcp.loader ' ));
360412 }
361413
414+ public function testRequestHandlerInterfaceAutoconfiguration ()
415+ {
416+ $ container = $ this ->buildContainer ([]);
417+ $ autoconfigured = $ container ->getAutoconfiguredInstanceof ();
418+ $ this ->assertArrayHasKey (RequestHandlerInterface::class, $ autoconfigured );
419+ $ definition = $ autoconfigured [RequestHandlerInterface::class];
420+ $ this ->assertTrue ($ definition ->hasTag ('mcp.request_handler ' ));
421+ }
422+
423+ public function testNotificationHandlerInterfaceAutoconfiguration ()
424+ {
425+ $ container = $ this ->buildContainer ([]);
426+ $ autoconfigured = $ container ->getAutoconfiguredInstanceof ();
427+ $ this ->assertArrayHasKey (NotificationHandlerInterface::class, $ autoconfigured );
428+ $ definition = $ autoconfigured [NotificationHandlerInterface::class];
429+ $ this ->assertTrue ($ definition ->hasTag ('mcp.notification_handler ' ));
430+ }
431+
362432 private function buildContainer (array $ configuration ): ContainerBuilder
363433 {
364434 $ container = new ContainerBuilder ();
0 commit comments