Lines 46.15% 12 / 26
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 10 / 10 100.00% 1 / 1 2
 runConsole 100.00% 1 / 1 100.00% 1 / 1 1
 getServerInfo 100.00% 1 / 1 100.00% 1 / 1 1
 createServerInfo 0.00% 0 / 14 0.00% 0 / 1 2
37class PhpMyFaqMcpServer implements McpServerRuntimeInterface
38{
39    private McpServerRuntimeInterface $runtime;
40
41    private const string MCP_SERVER_NAME = 'phpMyFAQ MCP Server';
42
43    public function __construct(
44        private readonly Configuration $configuration,
45        Language $language,
46        private readonly Search $search,
47        private readonly Faq $faq,
48        ?McpServerRuntimeInterface $runtime = null,
49    ) {
50        $detectionEnabled = (bool) $this->configuration->get(item: 'main.languageDetection');
51        $configLang = (string) $this->configuration->get(item: 'main.language');
52        $detectionEnabled
53            ? $language->setLanguageWithDetection($configLang)
54            : $language->setLanguageFromConfiguration($configLang);
55
56        $this->configuration->setLanguage($language);
57        $this->runtime = $runtime ?? new McpSdkRuntime(
58            new FaqSearchTool($this->configuration, $this->search, $this->faq),
59            $this->createServerInfo(),
60        );
61    }
62
63    /**
64     * Run the MCP server with console transport
65     */
66    public function runConsole(InputInterface $input, OutputInterface $output): void
67    {
68        $this->runtime->runConsole($input, $output);
69    }
70
71    /**
72     * Get server information for debugging
73     */
74    public function getServerInfo(): array
75    {
76        return $this->runtime->getServerInfo();
77    }
78
79    /**
80     * @return array<string, mixed>
81     */
82    private function createServerInfo(): array
83    {
84        return [
85            'name' => self::MCP_SERVER_NAME,
86            'version' => System::getMcpServerVersion(),
87            'description' => 'Model Context Protocol server for phpMyFAQ installations',
88            'capabilities' => [
89                'tools' => true,
90            ],
91            'tools' => [
92                [
93                    'name' => 'faq_search',
94                    'description' => 'Search through phpMyFAQ installations',
95                ],
96            ],
97        ];
98    }
99}