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
17 changes: 11 additions & 6 deletions src/mcp-bundle/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@

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'])
;
}

$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('setLogger', [service('monolog.logger.mcp')->nullOnInvalid()])
->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')])
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');
}

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

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