Make logger nullable in Transport constructors by camilleislasse · Pull Request #152 · modelcontextprotocol/php-sdk
- BaseTransport: Accept ?LoggerInterface parameter and convert null to NullLogger
- StdioTransport: Change logger parameter to nullable
- StreamableHttpTransport: Change logger parameter to nullable
- InMemoryTransport: Fix missing parent::__construct() call and add logging
Motivation and Context
Allow passing null as logger parameter to avoid verbose ternary operators when the logger is optional.
How Has This Been Tested?
- PHPUnit: All unit tests pass
- PHP-CS-Fixer: Clean
- PHPStan: No errors
Breaking Changes
No
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed