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)) {
$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
5 changes: 5 additions & 0 deletions src/mcp-bundle/tests/DependencyInjection/McpBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\AI\McpBundle\McpBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class McpBundleTest extends TestCase
Expand Down Expand Up @@ -49,6 +50,10 @@ public function testCustomConfiguration()

public function testMcpLoggerServiceIsCreated()
{
if (!class_exists(MonologBundle::class)) {
$this->markTestSkipped('MonologBundle is not installed');
}

Comment on lines +53 to +56

Choose a reason for hiding this comment

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

Since monolog is never installed on the ci, this test will be always skipped, so the rest of the test is useless. What do you think about requiring monolog on dev then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$container = $this->buildContainer([]);

$this->assertTrue($container->hasDefinition('monolog.logger.mcp'));
Expand Down
Loading