Refactor: Consolidate files, eliminate duplicate init patterns with generics, standardize validation naming #382
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.
Analysis identified duplicate init/close patterns, fragmented single-function files, and inconsistent validation file naming across the codebase.
Changes
File Consolidation
error_formatting.go→rpc_helpers.go(related RPC utilities)schema_normalizer.go→types.go(schema utilities with type definitions)Duplicate Code Elimination via Generics
Replaced 6 type-specific init/close helpers with 2 generic functions:
Validation File Naming Consistency
env_validation.go→validation_env.goschema_validation.go→validation_schema.goEstablishes
validation_*.gopattern for specialized validation modules.Impact
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
this-host-does-not-exist-12345.com/tmp/go-build1070877015/b278/mcp.test /tmp/go-build1070877015/b278/mcp.test -test.testlogfile=/tmp/go-build1070877015/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go1.25.5 -c=4 -nolocalimports -importcfg /tmp/go-build2965064099/b001/importcfg -pack /tmp/go-build2965064099/b001/_testmain.go 1023�� mat.go se.go x_amd64/compile(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Code Organization and Refactoring Opportunities</issue_title>
<issue_description>## Executive Summary
Analysis of 50 non-test Go files across 16 packages in the
internal/directory identified 5 high-priority refactoring opportunities focused on eliminating code duplication, improving file organization, and reducing file complexity. The analysis reveals duplicate initialization patterns, oversized files with mixed concerns, and opportunities to consolidate scattered functionality.Key Metrics:
Priority 1: Critical Refactoring Opportunities
1.⚠️ Logger Package - Duplicate Init/Close Patterns (HIGH IMPACT)
Issue: Six nearly identical functions with 100% duplicate logic, differing only by type
Location:
internal/logger/global_helpers.goDuplicate Functions:
Plus three matching
closeGlobal*Loggerfunctions with identical patterns.Code Similarity: 100% - Only type parameters differ
Recommendation: Use Go generics to consolidate into generic init/close functions:
Impact:
2.⚠️ Large File - MCP Connection (948 lines, 28 functions)
Issue: Single file handling too many distinct concerns, making it difficult to navigate and test
Location:
internal/mcp/connection.goCurrent Structure - Functions grouped by concern:
HTTP Transport Negotiation (3 functions):
tryStreamableHTTPTransport(line 317)trySSETransport(line 346)tryPlainJSONTransport(line 375)Response Parsing (1 function):
parseSSEResponse(line 25)Request Building (3 functions):
createJSONRPCRequest(line 104)ensureToolCallArguments(line 115)setupHTTPRequest(line 136)Connection Initialization (4 functions):
newMCPClient(line 75)newHTTPConnection(line 83)NewConnection(line 155)NewHTTPConnection(line 245)HTTP Session/Request Handling (2 functions):
initializeHTTPSession(line 495)sendHTTPRequest(line 603)MCP Method Implementations (6 functions):
listTools(line 736)callTool(line 757)listResources(line 800)readResource(line 821)listPrompts(line 852)getPrompt(line 873)Core Methods (4 functions):
IsHTTP,GetHTTPURL,GetHTTPHeaders(lines 401-411)SendRequest(line 417)SendRequestWithServerID(line 423)callSDKMethod(line 475)Close(line 942)Utility Functions (2 functions):
expandDockerEnvArgs(line 908)containsEqual(line 932)Recommended Split: