refactor: extract MCP client initialization logic into LifecyleInitializer #370
+786
−187
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.
Refactor MCP client initialization logic by extracting it from
McpAsyncClient
into a dedicatedLifecyleInitializer
class.This improves separation of concerns, maintainability, and testability of the initialization process.
Motivation and Context
The
McpAsyncClient
class was becoming too complex with initialization logic mixed in with client operations.This refactoring addresses several issues:
McpAsyncClient
interface is now cleaner and focused on its primary responsibilitiesHow Has This Been Tested?
LifecyleInitializerTests.java
covering:McpAsyncClient
tests continue to pass, ensuring backward compatibilityBreaking Changes
No breaking changes - This is an internal refactoring that maintains full API compatibility. All public methods of
McpAsyncClient
remain unchanged and behave identically.Types of changes
Note: While marked as potentially breaking, this is actually a non-breaking internal refactoring.
Checklist
Additional context
Implementation Notes:
LifecyleInitializer
follows the MCP specification for initialization phase requirementsMcpTransportSessionNotFoundException
with automatic re-initializationFiles Changed:
LifecyleInitializer.java
(348 lines) - Core initialization logicLifecyleInitializerTests.java
(403 lines) - Comprehensive test suiteMcpAsyncClient.java
- Simplified by delegating toLifecyleInitializer