|
19 | 19 |
|
20 | 20 | namespace phpMyFAQ\Service\McpServer; |
21 | 21 |
|
| 22 | +use Mcp\Server; |
| 23 | +use Mcp\Server\Transport\StdioTransport; |
22 | 24 | use phpMyFAQ\Configuration; |
23 | 25 | use RuntimeException; |
24 | 26 | use Symfony\Component\Console\Input\InputInterface; |
25 | 27 | use Symfony\Component\Console\Output\OutputInterface; |
26 | 28 |
|
27 | | -final class McpSdkRuntime implements McpServerRuntimeInterface |
| 29 | +final readonly class McpSdkRuntime implements McpServerRuntimeInterface |
28 | 30 | { |
29 | 31 | /** |
30 | 32 | * @param array<string, mixed> $serverInfo |
31 | 33 | */ |
32 | 34 | public function __construct( |
33 | | - private readonly Configuration $configuration, |
34 | | - private readonly FaqSearchTool $faqSearchTool, |
35 | | - private readonly array $serverInfo, |
| 35 | + private Configuration $configuration, |
| 36 | + private FaqSearchTool $faqSearchTool, |
| 37 | + private array $serverInfo, |
36 | 38 | ) { |
37 | 39 | } |
38 | 40 |
|
39 | 41 | public function runConsole(InputInterface $input, OutputInterface $output): void |
40 | 42 | { |
41 | | - $this->buildServer()->run(new \Mcp\Server\Transport\StdioTransport()); |
| 43 | + $this->buildServer()->run(new StdioTransport()); |
42 | 44 | } |
43 | 45 |
|
44 | 46 | public function getServerInfo(): array |
@@ -67,34 +69,29 @@ public function faqSearch( |
67 | 69 | 'all_languages' => $all_languages, |
68 | 70 | ]); |
69 | 71 |
|
70 | | - $decoded = json_decode($result['content'], true); |
| 72 | + $decoded = json_decode($result['content'], associative: true); |
71 | 73 |
|
72 | 74 | return json_last_error() === JSON_ERROR_NONE ? $decoded : $result['content']; |
73 | 75 | } |
74 | 76 |
|
75 | | - private function buildServer(): \Mcp\Server |
| 77 | + private function buildServer(): Server |
76 | 78 | { |
77 | | - if (!class_exists(\Mcp\Server::class) || !class_exists(\Mcp\Server\Transport\StdioTransport::class)) { |
| 79 | + if (!class_exists(Server::class) || !class_exists(StdioTransport::class)) { |
78 | 80 | throw new RuntimeException( |
79 | 81 | 'The mcp/sdk package is not installed or does not expose the expected server classes.', |
80 | 82 | ); |
81 | 83 | } |
82 | 84 |
|
83 | 85 | $definition = $this->faqSearchTool->getDefinition(); |
84 | 86 |
|
85 | | - return \Mcp\Server::builder() |
| 87 | + return Server::builder() |
86 | 88 | ->setServerInfo( |
87 | 89 | (string) $this->serverInfo['name'], |
88 | 90 | (string) $this->serverInfo['version'], |
89 | 91 | (string) ($this->serverInfo['description'] ?? null), |
90 | 92 | ) |
91 | 93 | ->addTool( |
92 | | - fn( |
93 | | - string $query, |
94 | | - ?int $category_id = null, |
95 | | - int $limit = 10, |
96 | | - bool $all_languages = false, |
97 | | - ): array|string => $this->faqSearch($query, $category_id, $limit, $all_languages), |
| 94 | + $this->faqSearch(...), |
98 | 95 | $definition->name, |
99 | 96 | $definition->description, |
100 | 97 | null, |
|
0 commit comments