mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-06-06 10:41:33 +00:00
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
*
|
|
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
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.');
|
|
}
|
|
}
|
|
}
|