PHP MCP Server v1.1.0
Added
- Manual Element Registration: Added fluent methods
withTool(),withResource(),withPrompt(), andwithResourceTemplate()to theServerclass. This allows programmatic registration of MCP elements as an alternative or supplement to attribute discovery. Both[ClassName::class, 'methodName']array handlers and invokable class string handlers are supported. - Invokable Class Attribute Discovery: The server's discovery mechanism now supports placing
#[Mcp*]attributes directly on invokable PHP class definitions (classes with a public__invokemethod). The__invokemethod will be used as the handler. - Discovery Path Configuration: Added
withBasePath(),withScanDirectories(), andwithExcludeDirectories()methods to theServerclass for finer control over which directories are scanned during attribute discovery.
Changed
- Dependency Injection: Refactored internal dependency management. Core server components (
Processor,Registry,TransportState, etc.) now resolveLoggerInterface,CacheInterface, andConfigurationRepositoryInterfaceJust-In-Time from the provided PSR-11 container. See Breaking Changes for implications. - Default Logging Behavior: Logging is now disabled by default. To enable logging, provide a
LoggerInterfaceimplementation viawithLogger()(when using the default container) or by registering it within your custom PSR-11 container. - Transport Handler Constructors: Transport Handlers (e.g.,
StdioTransportHandler,HttpTransportHandler) now primarily accept theServerinstance in their constructor, simplifying their instantiation.
Fixed
- Prevented potential "Constant STDERR not defined" errors in non-CLI environments by changing the default logger behavior (see Changed section).
Updated
- Extensively updated
README.mdto document manual registration, invokable class discovery, the dependency injection overhaul, discovery path configuration, transport handler changes, and the new default logging behavior.
Breaking Changes
- Dependency Injection Responsibility: Due to the DI refactoring, if you provide a custom PSR-11 container using
withContainer(), you MUST ensure that your container is configured to provide implementations forLoggerInterface,CacheInterface, andConfigurationRepositoryInterface. The server relies on being able to fetch these from the container. withLogger/Cache/ConfigBehavior with Custom Container: When a custom container is provided viawithContainer(), calls to->withLogger(),->withCache(), or->withConfig()on theServerinstance will not override the services resolved from your container during runtime. Configuration for these core services must be done directly within your custom container setup.- Transport Handler Constructor Signatures: The constructor signatures for
StdioTransportHandler,HttpTransportHandler, andReactPhpHttpTransportHandlerhave changed. They now primarily require theServerinstance. Update any direct instantiations of these handlers accordingly.
Full Changelog: 1.0.0...1.1.0