feat: Add Manual Registration, Invokable Discovery, and Refactor DI #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces several significant enhancements and refactors, aimed at increasing flexibility and improving robustness.
Key Changes:
withTool,withResource,withPrompt,withResourceTemplate) to theServerclass, allowing programmatic definition of MCP elements alongside attribute discovery. Supports[Class::class, 'method']array handlers and invokable class string handlers.Discovererto find#[Mcp*]attributes placed directly on invokable class definitions (classes with a public__invokemethod), using the__invokemethod as the handler.Processor,Registry,TransportState,Discoverer, etc.) now resolve essential dependencies (LoggerInterface,CacheInterface,ConfigurationRepositoryInterface) Just-In-Time from the configured PSR-11 container.withLogger/Cache/Configreplace defaults. When using a custom container viawithContainer(), providing these core interfaces (LoggerInterface,CacheInterface,ConfigurationRepositoryInterface) within the custom container is mandatory, and thewith*methods on theServerinstance do not override the container's configuration for these services during runtime.withBasePath(),withScanDirectories(), andwithExcludeDirectories()methods on theServerfor more precise configuration of directory scanning.HttpTransportHandler,StdioTransportHandler) to primarily accept theServerinstance, simplifying instantiation.README.mdsignificantly to cover all changes. Added new unit tests for manual registration and invokable discovery, and updated existing tests for DI refactoring.Breaking Changes:
withContainer()MUST ensureLoggerInterface,CacheInterface, andConfigurationRepositoryInterfaceare registered within their container. The behavior ofwithLogger/Cache/Configis altered when a custom container is present; configuration should happen directly in the container.Serverinstance. Integrations (especially for HTTP transports) will need to update handler instantiation.