Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
RunMcpServerCommand | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
configure | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\McpServer; |
3 | |
4 | use Apie\McpServer\Factory\RunnerFactoryInterface; |
5 | use Apie\McpServer\Tool\ToolFactory; |
6 | use Apie\McpServer\Tool\ToolRunner; |
7 | use Mcp\Server\Server; |
8 | use Symfony\Component\Console\Command\Command; |
9 | |
10 | class RunMcpServerCommand extends \Symfony\Component\Console\Command\Command |
11 | { |
12 | public function __construct( |
13 | private readonly RunnerFactoryInterface $runnerFactory, |
14 | private readonly ToolFactory $toolFactory, |
15 | private readonly ToolRunner $toolRunner, |
16 | ) { |
17 | parent::__construct('apie:mcp-server'); |
18 | } |
19 | |
20 | protected function configure() |
21 | { |
22 | $this |
23 | ->setDescription('Runs the MCP server to link with Apie') |
24 | ->setHelp('This command allows you to run the MCP server for Apie.'); |
25 | } |
26 | |
27 | protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output): int |
28 | { |
29 | $output->writeln("Creating MCP Server"); |
30 | $server = new Server('apie-server'); |
31 | $server->registerHandler('tools/list', function ($params) { |
32 | return $this->toolFactory->createList(); |
33 | }); |
34 | $server->registerHandler('tools/call', function ($params) { |
35 | $name = $params->name; |
36 | $tool = $this->toolFactory->findByName($name); |
37 | return $this->toolRunner->run($tool, $params); |
38 | }); |
39 | |
40 | $output->writeln('MCP Server is running...'); |
41 | $runner = $this->runnerFactory->createRunner($server); |
42 | $runner->run(); |
43 | $output->writeln('Runner has ended'); |
44 | return Command::SUCCESS; |
45 | } |
46 | } |