. */ declare(strict_types=1); namespace App\EventSubscriber; use App\Settings\AISettings\McpSettings; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\KernelEvents; readonly class McpAccessSubscriber implements EventSubscriberInterface { public function __construct(private McpSettings $mcpSettings) { } public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['onKernelRequest', 10], ]; } public function onKernelRequest(RequestEvent $event): void { if (!$event->isMainRequest()) { return; } $path = $event->getRequest()->getPathInfo(); if (!str_starts_with($path, '/mcp')) { return; } if (!$this->mcpSettings->enabled) { throw new ServiceUnavailableHttpException(null, 'The MCP endpoint is disabled. Enable it in the system settings.'); } } }