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