|
12 | 12 | namespace Symfony\AI\McpBundle\Tests\DependencyInjection; |
13 | 13 |
|
14 | 14 | use Mcp\Capability\Registry\Loader\LoaderInterface; |
| 15 | +use Mcp\Server\Handler\Notification\NotificationHandlerInterface; |
| 16 | +use Mcp\Server\Handler\Request\RequestHandlerInterface; |
15 | 17 | use PHPUnit\Framework\Attributes\DataProvider; |
16 | 18 | use PHPUnit\Framework\TestCase; |
17 | 19 | use Symfony\AI\McpBundle\McpBundle; |
| 20 | +use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; |
18 | 21 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
19 | 22 |
|
20 | 23 | class McpBundleTest extends TestCase |
@@ -150,13 +153,50 @@ public function testServerServices() |
150 | 153 | $methodCalls = $builderDefinition->getMethodCalls(); |
151 | 154 |
|
152 | 155 | $hasEventDispatcherCall = false; |
| 156 | + $hasRequestHandlers = false; |
| 157 | + $hasNotificationHandlers = false; |
| 158 | + $hasLoaders = false; |
| 159 | + |
153 | 160 | foreach ($methodCalls as $call) { |
154 | 161 | if ('setEventDispatcher' === $call[0]) { |
155 | 162 | $hasEventDispatcherCall = true; |
156 | | - break; |
| 163 | + } |
| 164 | + |
| 165 | + if ('addRequestHandlers' === $call[0]) { |
| 166 | + $argument = $call[1][0]; |
| 167 | + if ( |
| 168 | + $argument instanceof TaggedIteratorArgument |
| 169 | + && 'mcp.request_handler' === $argument->getTag() |
| 170 | + ) { |
| 171 | + $hasRequestHandlers = true; |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + if ('addNotificationHandlers' === $call[0]) { |
| 176 | + $argument = $call[1][0]; |
| 177 | + if ( |
| 178 | + $argument instanceof TaggedIteratorArgument |
| 179 | + && 'mcp.notification_handler' === $argument->getTag() |
| 180 | + ) { |
| 181 | + $hasNotificationHandlers = true; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + if ('addLoaders' === $call[0]) { |
| 186 | + $argument = $call[1][0]; |
| 187 | + if ( |
| 188 | + $argument instanceof TaggedIteratorArgument |
| 189 | + && 'mcp.loader' === $argument->getTag() |
| 190 | + ) { |
| 191 | + $hasLoaders = true; |
| 192 | + } |
157 | 193 | } |
158 | 194 | } |
| 195 | + |
159 | 196 | $this->assertTrue($hasEventDispatcherCall, 'ServerBuilder should have setEventDispatcher method call'); |
| 197 | + $this->assertTrue($hasRequestHandlers, 'ServerBuilder should have addRequestHandlers with mcp.request_handler tag'); |
| 198 | + $this->assertTrue($hasNotificationHandlers, 'ServerBuilder should have addNotificationHandlers with mcp.notification_handler tag'); |
| 199 | + $this->assertTrue($hasLoaders, 'ServerBuilder should have addLoaders with mcp.loader tag'); |
160 | 200 | } |
161 | 201 |
|
162 | 202 | public function testMcpToolAttributeAutoconfiguration() |
@@ -359,6 +399,24 @@ public function testLoaderInterfaceAutoconfiguration() |
359 | 399 | $this->assertTrue($definition->hasTag('mcp.loader')); |
360 | 400 | } |
361 | 401 |
|
| 402 | + public function testRequestHandlerInterfaceAutoconfiguration() |
| 403 | + { |
| 404 | + $container = $this->buildContainer([]); |
| 405 | + $autoconfigured = $container->getAutoconfiguredInstanceof(); |
| 406 | + $this->assertArrayHasKey(RequestHandlerInterface::class, $autoconfigured); |
| 407 | + $definition = $autoconfigured[RequestHandlerInterface::class]; |
| 408 | + $this->assertTrue($definition->hasTag('mcp.request_handler')); |
| 409 | + } |
| 410 | + |
| 411 | + public function testNotificationHandlerInterfaceAutoconfiguration() |
| 412 | + { |
| 413 | + $container = $this->buildContainer([]); |
| 414 | + $autoconfigured = $container->getAutoconfiguredInstanceof(); |
| 415 | + $this->assertArrayHasKey(NotificationHandlerInterface::class, $autoconfigured); |
| 416 | + $definition = $autoconfigured[NotificationHandlerInterface::class]; |
| 417 | + $this->assertTrue($definition->hasTag('mcp.notification_handler')); |
| 418 | + } |
| 419 | + |
362 | 420 | private function buildContainer(array $configuration): ContainerBuilder |
363 | 421 | { |
364 | 422 | $container = new ContainerBuilder(); |
|
0 commit comments