Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mcp-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11.5"
"phpunit/phpunit": "^11.5",
"symfony/monolog-bundle": "^3.10"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
23 changes: 16 additions & 7 deletions src/mcp-bundle/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,33 @@

use Mcp\Server;
use Mcp\Server\Builder;
use Symfony\Bundle\MonologBundle\MonologBundle;

return static function (ContainerConfigurator $container): void {
$container->services()
->set('monolog.logger.mcp')
->parent('monolog.logger_prototype')
->args(['mcp'])
->tag('monolog.logger', ['channel' => 'mcp'])
if (class_exists(MonologBundle::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the bundle class exists does not mean that the bundle is loaded/enabled.

$container->services()
->set('monolog.logger.mcp')
->parent('monolog.logger_prototype')
->args(['mcp'])
->tag('monolog.logger', ['channel' => 'mcp'])
;
}

$builderDefinition = $container->services()
->set('mcp.server.builder', Builder::class)
->factory([Server::class, 'builder'])
->call('setServerInfo', [param('mcp.app'), param('mcp.version')])
->call('setPaginationLimit', [param('mcp.pagination_limit')])
->call('setInstructions', [param('mcp.instructions')])
->call('setLogger', [service('monolog.logger.mcp')])
->call('setEventDispatcher', [service('event_dispatcher')])
->call('setSession', [service('mcp.session.store')])
->call('setDiscovery', [param('kernel.project_dir'), param('mcp.discovery.scan_dirs'), param('mcp.discovery.exclude_dirs')])
->call('setDiscovery', [param('kernel.project_dir'), param('mcp.discovery.scan_dirs'), param('mcp.discovery.exclude_dirs')]);

if (class_exists(MonologBundle::class)) {
$builderDefinition->call('setLogger', [service('monolog.logger.mcp')]);
}

$container->services()
->set('mcp.server', Server::class)
->factory([service('mcp.server.builder'), 'build'])

Expand Down
2 changes: 1 addition & 1 deletion src/mcp-bundle/src/Command/McpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class McpCommand extends Command
{
public function __construct(
private readonly Server $server,
private readonly LoggerInterface $logger,
private readonly ?LoggerInterface $logger = null,
) {
parent::__construct();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mcp-bundle/src/McpBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function configureClient(array $transports, array $httpConfig, Container
$container->register('mcp.server.command', McpCommand::class)
->setArguments([
new Reference('mcp.server'),
new Reference('logger'),
new Reference('monolog.logger.mcp', ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
->addTag('console.command');
}
Expand Down
Loading