Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
…ation Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis for code organization
Refactor: Code organization improvements from semantic clustering analysis
Feb 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements code organization improvements identified through semantic clustering analysis. The changes focus on reducing code duplication, improving file organization, and removing unnecessary wrapper functions.
Changes:
- Extracted duplicate auth middleware conditional logic into
applyAuthIfConfigured()helper function - Moved generic
logRuntimeError()function fromauth.goto dedicatederrors.gofile - Separated 86-line
NormalizeInputSchema()transformation logic fromtypes.gointo newschema.gofile - Removed thin
validateServerConfig()wrapper function that only passednilparameter
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/server/transport.go | Added applyAuthIfConfigured() helper to eliminate duplicate conditional auth middleware application (8 lines of duplication removed) |
| internal/server/errors.go | New file containing logRuntimeError() utility, properly isolating generic error handling from auth-specific logic |
| internal/server/auth.go | Removed logRuntimeError() function and cleaned up unused imports (log, time) |
| internal/mcp/schema.go | New file containing NormalizeInputSchema() function with improved documentation, separating transformation logic from type definitions |
| internal/mcp/types.go | Removed schema transformation logic, now contains only type definitions per Go conventions |
| internal/config/validation.go | Removed unnecessary validateServerConfig() wrapper function |
| internal/config/validation_test.go | Updated test to call validateServerConfigWithCustomSchemas() directly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Semantic function clustering analysis identified 4 high-priority refactoring opportunities: duplicate auth middleware application, misplaced generic utilities, schema transformation mixed with type definitions, and unnecessary wrapper indirection.
Changes
Extract auth middleware helper
applyAuthIfConfigured()helperinternal/server/transport.goBefore:
After:
Move runtime error logging to dedicated file
internal/server/errors.gofor error handling utilitieslogRuntimeError()fromauth.go(was incorrectly placed in auth-specific file)Separate schema transformation from type definitions
internal/mcp/schema.gofor 86-lineNormalizeInputSchema()functioninternal/mcp/types.gonow contains only type definitions per Go conventionsRemove validation wrapper
validateServerConfig()wrapper that only passednilvalidateServerConfigWithCustomSchemas()directlyFiles Changed
internal/server/transport.go,internal/server/auth.go,internal/mcp/types.go,internal/config/validation.go,internal/config/validation_test.gointernal/server/errors.go,internal/mcp/schema.goWarning
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:
example.com/tmp/go-build1870635187/b275/launcher.test /tmp/go-build1870635187/b275/launcher.test -test.testlogfile=/tmp/go-build1870635187/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ain cfg s.test --gdwarf-5 --64 -o s.test 6525�� ache/go/1.25.7/x-s -I 86_64/git --gdwarf-5 --64 -o 256506/b165/_x00-extld=gcc(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build1870635187/b260/config.test /tmp/go-build1870635187/b260/config.test -test.testlogfile=/tmp/go-build1870635187/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true d -n 10 5877973+lpcox@users.noreply.github.com> 64/pkg/tool/linux_amd64/vet -p net/netip -lang=go1.25 64/pkg/tool/linux_amd64/vet -I /opt/hostedtoolcache/go/1.25.7/x64/src/runtime/cgo 256506/b165/ x_amd64/link --gdwarf-5 --64(dns block)/tmp/go-build3740779677/b001/config.test /tmp/go-build3740779677/b001/config.test -test.testlogfile=/tmp/go-build3740779677/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -uns�� on-clustering-again /tmp/go-build165256506/b208/vet.cfg .12/x64/bin/bash(dns block)nonexistent.local/tmp/go-build1870635187/b275/launcher.test /tmp/go-build1870635187/b275/launcher.test -test.testlogfile=/tmp/go-build1870635187/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ain cfg s.test --gdwarf-5 --64 -o s.test 6525�� ache/go/1.25.7/x-s -I 86_64/git --gdwarf-5 --64 -o 256506/b165/_x00-extld=gcc(dns block)slow.example.com/tmp/go-build1870635187/b275/launcher.test /tmp/go-build1870635187/b275/launcher.test -test.testlogfile=/tmp/go-build1870635187/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ain cfg s.test --gdwarf-5 --64 -o s.test 6525�� ache/go/1.25.7/x-s -I 86_64/git --gdwarf-5 --64 -o 256506/b165/_x00-extld=gcc(dns block)this-host-does-not-exist-12345.com/tmp/go-build1870635187/b284/mcp.test /tmp/go-build1870635187/b284/mcp.test -test.testlogfile=/tmp/go-build1870635187/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true rverConfigWithCustomSchemas 256506/b082/vet.cfg cfg --gdwarf-5 ut-2576538208.c -o ache/go/1.25.7/x-importcfg(dns block)/tmp/go-build3437160695/b284/mcp.test /tmp/go-build3437160695/b284/mcp.test -test.testlogfile=/tmp/go-build3437160695/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build1870635187/b305/importcfg -pack /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/version/version.go /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/version/version_test.go -qui�� ain /opt/hostedtoolcache/go/1.25.7/x64/src/net x_amd64/compile /tmp/go-build165/opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/compile -imultiarch x86_64-linux-gnu/tmp/go-build1870635187/b306/_pkg_.a x_amd64/compile(dns block)Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com> 64/bin/git -plugin-opt=-pas/usr/libexec/docker/cli-plugins/docker-buildx -plugin-opt=-pasdocker-cli-plugin-metadata -plugin-opt=-pass-through=-lpthr(create|run) /opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/vet` (dns block)
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Code Organization & Refactoring Opportunities</issue_title>
<issue_description>## Executive Summary
Analyzed 63 Go source files (excluding tests) across 16 packages containing ~450 functions to identify refactoring opportunities through semantic function clustering and duplicate detection.
Key Findings:
Analysis covered:
internal/directoryPackage Overview
Files by Package
Identified Issues
Priority 1: High-Impact Refactoring
1. Duplicate Auth Middleware Application (server package)
Issue: Auth middleware is applied with identical pattern in two places.
Location:
internal/server/transport.go:120-122and137-139Current Code Pattern:
Recommendation: Extract to helper function
Estimated Impact: Reduced duplication, easier maintenance
Effort: 30 minutes
2. Misplaced Generic Logging Function (server package)
Issue: Generic runtime error logging function is in auth-specific file.
Function:
logRuntimeError()ininternal/server/auth.goProblem: This function logs generic runtime errors and panics, not authentication-specific errors.
Current Location:
internal/server/auth.go(lines ~50-60)Recommendation: Move to
internal/server/server.goor createinternal/server/errors.gofor error handling utilities.Estimated Impact: Improved code organization, clearer file purpose
Effort: 15 minutes
3. Large Schema Normalization Function in Types File (mcp package)
Issue: 86-line schema normalization logic mixed with type definitions.
Function:
NormalizeInputSchema()ininternal/mcp/types.goProblem:
types.goshould contain simple type definitions, not complex transformation logic.Current: 86 lines of schema transformation logic in types.go
Better: Extract to
internal/mcp/schema.goorinternal/mcp/normalize.goRecommendation:
internal/mcp/schema.goNormalizeInputSchema()to new filetypes.goEstimated Impact: Clearer separation of concerns, easier to test
Effort: 20 minutes
4. Unnecessary Validation Wrapper Function (config package)
Issue: Thin wrapper function that adds no value.
Function:
validateServerConfig()ininternal/config/validation.go:104-106Current Code:
Problem: This wrapper just calls the main function with
nilas the last parameter.Recommendation: Remove wrapper, call `validateServerConfigWithCustomSchem...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.