Skip to content

PHP MCP Server v1.1.0

Choose a tag to compare

@CodeWithKyrian CodeWithKyrian released this 01 May 16:59
· 108 commits to main since this release
2ff0f7d

Added

  • Manual Element Registration: Added fluent methods withTool(), withResource(), withPrompt(), and withResourceTemplate() to the Server class. 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 __invoke method). The __invoke method will be used as the handler.
  • Discovery Path Configuration: Added withBasePath(), withScanDirectories(), and withExcludeDirectories() methods to the Server class 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 resolve LoggerInterface, CacheInterface, and ConfigurationRepositoryInterface Just-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 LoggerInterface implementation via withLogger() (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 the Server instance 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.md to 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 for LoggerInterface, CacheInterface, and ConfigurationRepositoryInterface. The server relies on being able to fetch these from the container.
  • withLogger/Cache/Config Behavior with Custom Container: When a custom container is provided via withContainer(), calls to ->withLogger(), ->withCache(), or ->withConfig() on the Server instance 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, and ReactPhpHttpTransportHandler have changed. They now primarily require the Server instance. Update any direct instantiations of these handlers accordingly.

Full Changelog: 1.0.0...1.1.0