Skip to content

Conversation

@camilleislasse
Copy link

@camilleislasse camilleislasse commented Nov 13, 2025

Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #830
License MIT

This PR makes MonologBundle optional dependency for McpBundle. Without it installed, the container compilation was failing with "Parent definition' monolog.logger_prototype' does not exist."

Changes

  • Wrap monolog.logger.mcp service creation in class_exists() check
  • Add ->nullOnInvalid() to setLogger() call in services.php
  • Uniformize logger references: both McpCommand and McpController now use monolog.logger.mcp with NULL_ON_INVALID_REFERENCE
  • Update test to skip when MonologBundle is not installed

Credits

Builds on the initial work in #849 by @WebMamba. That PR protected service creation but the service was still referenced without protection. This PR completes the fix by also protecting the service usage.

Fixes symfony#830

- Wrap monolog.logger.mcp service creation in class_exists() check
- Add ->nullOnInvalid() to setLogger() call
- Uniformize logger references in McpCommand and McpController
- Update test to skip when MonologBundle is not installed

Builds on symfony#849 by @WebMamba
@carsonbot carsonbot added Bug Something isn't working Status: Needs Review labels Nov 13, 2025
@carsonbot carsonbot changed the title Make MonologBundle optional in McpBundle Make MonologBundle optional in McpBundle Nov 13, 2025
@OskarStark OskarStark added the MCP Bundle Issues & PRs about the MCP SDK integration bundle label Nov 13, 2025
@carsonbot carsonbot changed the title Make MonologBundle optional in McpBundle [MCP Bundle] Make MonologBundle optional in McpBundle Nov 13, 2025
@OskarStark OskarStark changed the title [MCP Bundle] Make MonologBundle optional in McpBundle [MCP Bundle] Make MonologBundle optional Nov 13, 2025
Copy link

@WebMamba WebMamba left a comment

Choose a reason for hiding this comment

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

Thanks @camilleislasse to give me a hand on this.

Comment on lines +53 to +56
if (!class_exists(MonologBundle::class)) {
$this->markTestSkipped('MonologBundle is not installed');
}

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
Author

Choose a reason for hiding this comment

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

->call('setPaginationLimit', [param('mcp.pagination_limit')])
->call('setInstructions', [param('mcp.instructions')])
->call('setLogger', [service('monolog.logger.mcp')])
->call('setLogger', [service('monolog.logger.mcp')->nullOnInvalid()])

Choose a reason for hiding this comment

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

The function setLogger can't have a nullable as argument see:
https://github.com/modelcontextprotocol/php-sdk/blob/7a3b473c405411aca8be14c0c6e12d2493752d61/src/Server/Builder.php#L254.
So I don't think this can work... Maybe to have an if condition before the call can be better ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes and another error probably here :

private readonly LoggerInterface $logger,

Copy link
Author

@camilleislasse camilleislasse Nov 14, 2025

Choose a reason for hiding this comment

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

I'm not entirely happy with this solution ecea6d6 - conditionally instantiating transports with/without the logger parameter feels verbose.

The issue: MCP SDK has LoggerInterface $logger = new NullLogger() (non-nullable), so we can't pass null even though there's a default, if you have a better idea @WebMamba

Can change if modelcontextprotocol/php-sdk#152 is correct

…ts, and handle nullable logger in McpCommand/McpController by conditionally passing it to Transports.

  When MonologBundle is absent, Server and Transports use their default NullLogger.
@OskarStark
Copy link
Contributor

I tend more and more to require the logger

@camilleislasse
Copy link
Author

I tend more and more to require the logger

Me too, I feel like we’re making things unnecessarily complicated 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working MCP Bundle Issues & PRs about the MCP SDK integration bundle Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MCP Bundle] missing requirement to monolog

4 participants