-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathMcpServerBundle.php
More file actions
60 lines (50 loc) · 2.36 KB
/
McpServerBundle.php
File metadata and controls
60 lines (50 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
namespace PhpMcp\Server\Bridge\Symfony;
use PhpMcp\Server\Bridge\Symfony\Command\McpServerStartCommand;
use PhpMcp\Server\Bridge\Symfony\DependencyInjection\Compiler\McpServerPass;
use PhpMcp\Server\Contracts\McpElementInterface;
use PhpMcp\Server\Server;
use PhpMcp\Server\ServerBuilder;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
class McpServerBundle extends AbstractBundle
{
public function configure(DefinitionConfigurator $definition): void
{
$definition->rootNode()
->children()
->scalarNode('logger')->cannotBeEmpty()->defaultValue('logger')->end()
->arrayNode('server_info')
->isRequired()
->children()
->scalarNode('name')->isRequired()->cannotBeEmpty()->end()
->scalarNode('version')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end();
}
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$container->services()
->set('mcp_server.server_builder', ServerBuilder::class)
->factory([Server::class, 'make'])
->call('withLogger', [service($config['logger'])])
->call('withServerInfo', [$config['server_info']['name'], $config['server_info']['version']])
->set('mcp_server.server', Server::class)
->factory([service('mcp_server.server_builder'), 'build'])
->alias(Server::class, 'mcp_server.server')
->set('mcp_server.command.server_start', McpServerStartCommand::class)
->args([service('mcp_server.server')])
->tag('console.command');
$builder->registerForAutoconfiguration(McpElementInterface::class)->addTag('mcp_server.server_element');
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new McpServerPass());
}
}