diff --git a/config/packages/mcp.yaml b/config/packages/mcp.yaml index cabcad1b..4c2a9ea9 100644 --- a/config/packages/mcp.yaml +++ b/config/packages/mcp.yaml @@ -1,4 +1,12 @@ mcp: + app: "Part-DB" + version: "0.1.0" + description: "Part-DB is a inventory management database for electronic parts." + instructions: | + This server provides inventory information for your current user. It is mostly used for electronic parts, + but can be used for any kind of inventory. The stored objects are called parts. + If you miss some information from an search endpoint, try to retrieve more details using the ID of an entity. + client_transports: http: true stdio: false diff --git a/src/EventSubscriber/McpAccessSubscriber.php b/src/EventSubscriber/McpAccessSubscriber.php new file mode 100644 index 00000000..c7cab6e2 --- /dev/null +++ b/src/EventSubscriber/McpAccessSubscriber.php @@ -0,0 +1,60 @@ +. + */ + +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.'); + } + } +} diff --git a/src/Settings/AISettings/AISettings.php b/src/Settings/AISettings/AISettings.php index 732eb597..14544c04 100644 --- a/src/Settings/AISettings/AISettings.php +++ b/src/Settings/AISettings/AISettings.php @@ -35,6 +35,9 @@ class AISettings { use SettingsTrait; + #[EmbeddedSettings] + public ?McpSettings $mcp = null; + #[EmbeddedSettings] public ?OpenRouterSettings $openRouter = null; diff --git a/src/Settings/AISettings/McpSettings.php b/src/Settings/AISettings/McpSettings.php new file mode 100644 index 00000000..929efa41 --- /dev/null +++ b/src/Settings/AISettings/McpSettings.php @@ -0,0 +1,45 @@ +. + */ + +declare(strict_types=1); + +namespace App\Settings\AISettings; + +use App\Settings\SettingsIcon; +use Jbtronics\SettingsBundle\Metadata\EnvVarMode; +use Jbtronics\SettingsBundle\Settings\Settings; +use Jbtronics\SettingsBundle\Settings\SettingsParameter; +use Jbtronics\SettingsBundle\Settings\SettingsTrait; +use Symfony\Component\Translation\TranslatableMessage as TM; + +#[Settings(label: new TM("settings.misc.mcp"))] +#[SettingsIcon("fa-robot")] +class McpSettings +{ + use SettingsTrait; + + #[SettingsParameter( + label: new TM("settings.misc.mcp.enabled"), + description: new TM("settings.misc.mcp.enabled.help"), + envVar: "bool:MCP_ENABLED", + envVarMode: EnvVarMode::OVERWRITE, + )] + public bool $enabled = false; +} diff --git a/translations/messages.de.xlf b/translations/messages.de.xlf index f736121a..8908dcaf 100644 --- a/translations/messages.de.xlf +++ b/translations/messages.de.xlf @@ -1,6 +1,6 @@ - + attachment_type.caption @@ -10034,6 +10034,24 @@ Bitte beachten Sie, dass Sie sich nicht als deaktivierter Benutzer ausgeben kön Servereinstellungen + + + settings.misc.mcp + MCP (Model Context Protocol) Server + + + + + settings.misc.mcp.enabled + MCP-Endpunkt aktivieren + + + + + settings.misc.mcp.enabled.help + Aktiviert den MCP-Endpunkt (Model Context Protocol) unter /mcp, der es KI-Assistenten ermöglicht, mit Part-DB zu interagieren. + + settings.misc.kicad_eda diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 11dcbd8e..760b01e1 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -10035,6 +10035,24 @@ Please note, that you can not impersonate a disabled user. If you try you will g Server settings + + + settings.misc.mcp + MCP (Model Context Protocol) Server + + + + + settings.misc.mcp.enabled + Enable MCP endpoint + + + + + settings.misc.mcp.enabled.help + Enable the MCP (Model Context Protocol) endpoint at /mcp, which allows AI assistants to interact with Part-DB. + + settings.misc.kicad_eda