You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analysis of repository: github/gh-aw-mcpg β July 2026
Executive Summary
This analysis examined 156 non-test Go source files across 26 packages in internal/, cataloguing ~964 functions. The codebase is generally well-organized with clear package boundaries. However, three categories of actionable refactoring opportunities were identified: (1) small single-function packages that could be consolidated with related packages, (2) a few functions that feel slightly misplaced given their file/package context, and (3) two response-writer types that have intentionally-shared base logic already centralized (good pattern worth calling out).
Full Report
Function Inventory
Package Summary
Package
Files
~Functions
Primary Purpose
internal/server
21
134
HTTP server, routing, sessions, tools
internal/config
18
130
Config parsing, validation
internal/difc
12
124
DIFC security labels
internal/logger
16
122
Debug/file/RPC logging
internal/guard
12
79
WASM guards, label agents
internal/mcp
11
73
MCP protocol, connections, transports
internal/proxy
7
52
GitHub API filtering proxy
internal/cmd
14
41
CLI (Cobra flags/commands)
internal/launcher
4
39
Docker backend process management
internal/tracing
7
38
OpenTelemetry tracing
internal/middleware
2
21
jq schema processing
internal/util
6
19
String, format, random, collection utils
internal/httputil
4
17
Generic HTTP helpers, TLS
internal/envutil
4
13
Environment variable utilities
internal/sys
2
12
Container/Docker detection
internal/githubhttp
4
10
GitHub API HTTP helpers
internal/sanitize
1
8
Secret redaction
internal/auth
2
8
Auth header parsing
internal/oidc
1
6
OIDC token provider
internal/syncutil
2
5
Concurrency utilities
internal/version
1
5
Version management
internal/urlutil
1
3
URL domain extraction
internal/mcpresult
1
2
MCP result text helpers
internal/jqutil
1
1
gojq compiler options
internal/tty
2
2
Terminal detection
Identified Issues
1. Micro-packages That Could Be Consolidated
Several single-file packages contain very few functions and serve closely related purposes to larger packages. Keeping them as separate packages adds import overhead for consumers.
Issue: Package comment itself notes this exists only to share gojq compile options between internal/config and internal/middleware. It is a pure leaf-utility with no domain semantics.
Recommendation: Merge into internal/middleware (the primary consumer) and expose the SecureCompileOpts variable from there, updating the single import in internal/config/validation_server.go.
Estimated Effort: 30 minutes
Impact: Removes one import path; the package comment's stated purpose becomes moot.
Issue: These are pure helpers for interpreting MCP tool-call result content. They operate directly on MCP protocol structures and belong logically in internal/mcp.
Recommendation: Move both functions into internal/mcp/tool_result.go (which already contains ParseToolArguments and related MCP result helpers).
Estimated Effort: 30 minutes
Impact: Consolidates all MCP result processing in one location; removes a thin package.
Issue: URL domain extraction is used exclusively by internal/middleware and internal/logger for domain audit logging. This is a narrow utility tightly coupled to the middleware audit feature.
Recommendation: Consider moving into internal/middleware (primary consumer) or keeping as-is if other consumers are anticipated. Low priority since it is already a small, clean package.
Estimated Effort: 30 minutes
Impact: Minor consolidation.
2. Outlier Functions (Functions in Files with Mismatched Purpose)
Function: MountFormat(mount, jsonPath string, index int) *ValidationError (line 125)
Issue: All other exported functions in validation_rules.go follow the verb-noun pattern (PortRange, TimeoutPositive, AbsolutePath, RequiredStringField, etc.). MountFormat uses noun-verb order and is called from a helper mountValidationError on line 108. The name suggests formatting, not validation.
Recommendation: Rename to MountPath or ValidateMount to match the file's naming convention, or relocate the mount-specific logic to validation_server.go (where validateMounts already lives).
Issue: These are DIFC-specific log formatting helpers placed in internal/server because they reference server-level logging. They duplicate the conceptual responsibility of internal/difc/violations.go (which already has FormatViolationError, formatIntegrityLevel, formatSecrecyLevel). The split makes it harder to understand the complete picture of how DIFC violations are presented.
Recommendation: This is an acceptable tradeoff (the functions need server-level logger references). Document the split explicitly, or consider moving the formatting helpers to internal/difc/violations.go and passing in a string-returning logger helper.
Estimated Effort: 2β3 hours if moved
Impact: Better cohesion of DIFC formatting logic.
internal/cmd/proxy.go β proxyForcePublicReposIfNeeded policy logic in CLI
Issue: This function makes a GitHub API call to determine repository visibility and modifies a policy JSON string. It contains business logic (repo visibility + policy mutation) that lives in a CLI command file, making it harder to test independently.
Recommendation: Move to internal/config/guard_policy_parse.go or a new internal/config/guard_policy_resolve.go, where it sits alongside ResolveGuardPolicyOverride and BuildAllowOnlyPolicy.
Estimated Effort: 1β2 hours
Impact: Improved testability; CLI file becomes a thin orchestrator.
internal/httputil/response_writer.go defines BaseResponseWriter (status-code capture), and internal/server/response_writer.go embeds it, adding body buffering. This is the correct Go embedding pattern β not a duplication. The httputil package comment explicitly says to embed BaseResponseWriter to avoid duplicating status-capture boilerplate. β
The jqutil package was intentionally created to prevent $ENV-disable options from drifting apart between config and middleware. The intent is sound; the question is only whether a one-function package is the right level of abstraction (see Issue 1 above).
The 8 validation_*.go files in internal/config/ are well-organized: each file owns one validation domain (errors, rules, server, gateway, env, schema, tracing, shared). This is a good example of the single-responsibility-per-file principle. β
Assessment: guard/context.go manages DIFC-specific context keys (difc-agent-id, difc-request-state). Its package comment explains the intentional split from internal/auth. Acceptable as-is, though the file could be renamed difc_context.go for clarity.
Refactoring Recommendations
Priority 1: Quick Wins (< 1 hour each)
Merge internal/mcpresult into internal/mcp/tool_result.go
Move NormalizeContentItems and ExtractTextContent
Update all import sites
Removes a thin package with only 2 functions
Rename MountFormat β MountPath in internal/config/validation_rules.go
Aligns with the verb-noun convention of the file
Update the single call site in mountValidationError
π§ Semantic Function Clustering Analysis
Analysis of repository: github/gh-aw-mcpg β July 2026
Executive Summary
This analysis examined 156 non-test Go source files across 26 packages in
internal/, cataloguing ~964 functions. The codebase is generally well-organized with clear package boundaries. However, three categories of actionable refactoring opportunities were identified: (1) small single-function packages that could be consolidated with related packages, (2) a few functions that feel slightly misplaced given their file/package context, and (3) two response-writer types that have intentionally-shared base logic already centralized (good pattern worth calling out).Full Report
Function Inventory
Package Summary
internal/serverinternal/configinternal/difcinternal/loggerinternal/guardinternal/mcpinternal/proxyinternal/cmdinternal/launcherinternal/tracinginternal/middlewareinternal/utilinternal/httputilinternal/envutilinternal/sysinternal/githubhttpinternal/sanitizeinternal/authinternal/oidcinternal/syncutilinternal/versioninternal/urlutilinternal/mcpresultinternal/jqutilinternal/ttyIdentified Issues
1. Micro-packages That Could Be Consolidated
Several single-file packages contain very few functions and serve closely related purposes to larger packages. Keeping them as separate packages adds import overhead for consumers.
internal/jqutilβ 1 function, 1 fileinternal/jqutil/secure.goCompileOptsWithVariables(varNames []string) []gojq.CompilerOptioninternal/configandinternal/middleware. It is a pure leaf-utility with no domain semantics.internal/middleware(the primary consumer) and expose theSecureCompileOptsvariable from there, updating the single import ininternal/config/validation_server.go.internal/mcpresultβ 2 functions, 1 fileinternal/mcpresult/mcpresult.goNormalizeContentItems,ExtractTextContentinternal/mcp.internal/mcp/tool_result.go(which already containsParseToolArgumentsand related MCP result helpers).internal/urlutilβ 3 functions, 1 fileinternal/urlutil/domains.goExtractURLDomainsFromValue,collectURLDomains,ExtractURLDomainsinternal/middlewareandinternal/loggerfor domain audit logging. This is a narrow utility tightly coupled to the middleware audit feature.internal/middleware(primary consumer) or keeping as-is if other consumers are anticipated. Low priority since it is already a small, clean package.2. Outlier Functions (Functions in Files with Mismatched Purpose)
internal/config/validation_rules.goβMountFormatnaming inconsistencyinternal/config/validation_rules.goMountFormat(mount, jsonPath string, index int) *ValidationError(line 125)validation_rules.gofollow the verb-noun pattern (PortRange,TimeoutPositive,AbsolutePath,RequiredStringField, etc.).MountFormatuses noun-verb order and is called from a helpermountValidationErroron line 108. The name suggests formatting, not validation.MountPathorValidateMountto match the file's naming convention, or relocate the mount-specific logic tovalidation_server.go(wherevalidateMountsalready lives).internal/server/difc_log.goβ DIFC log helpers split from DIFC packageinternal/server/difc_log.gologFilteredItems,buildFilteredItemLogEntry,buildDIFCSingleItemFilteredError,buildDIFCFilteredNotice,difcPolicyLabelinternal/serverbecause they reference server-level logging. They duplicate the conceptual responsibility ofinternal/difc/violations.go(which already hasFormatViolationError,formatIntegrityLevel,formatSecrecyLevel). The split makes it harder to understand the complete picture of how DIFC violations are presented.internal/difc/violations.goand passing in a string-returning logger helper.internal/cmd/proxy.goβproxyForcePublicReposIfNeededpolicy logic in CLIinternal/cmd/proxy.go(line 348)proxyForcePublicReposIfNeeded(ctx context.Context, policyJSON, token, apiURL string) stringinternal/config/guard_policy_parse.goor a newinternal/config/guard_policy_resolve.go, where it sits alongsideResolveGuardPolicyOverrideandBuildAllowOnlyPolicy.3. Well-Designed Patterns Worth Preserving
httputil.BaseResponseWriterβ intentional inheritanceinternal/httputil/response_writer.godefinesBaseResponseWriter(status-code capture), andinternal/server/response_writer.goembeds it, adding body buffering. This is the correct Go embedding pattern β not a duplication. Thehttputilpackage comment explicitly says to embedBaseResponseWriterto avoid duplicating status-capture boilerplate. βinternal/jqutil.SecureCompileOptsβ centralized security optionsThe jqutil package was intentionally created to prevent
$ENV-disable options from drifting apart betweenconfigandmiddleware. The intent is sound; the question is only whether a one-function package is the right level of abstraction (see Issue 1 above).internal/config/validation_*split β appropriate decompositionThe 8
validation_*.gofiles ininternal/config/are well-organized: each file owns one validation domain (errors, rules, server, gateway, env, schema, tracing, shared). This is a good example of the single-responsibility-per-file principle. βClustering Results Summary
Cluster: Validation Functions
internal/config/validation_*.go(8 files, ~80 functions) βinternal/sys/docker.go:ValidateContainerID,internal/server/session.go:extractAndValidateSession,internal/server/guard_visibility.go:validateSinkVisibilityExemptServersCluster: Parse Functions
internal/mcp/,internal/auth/,internal/githubhttp/,internal/config/,internal/difc/,internal/guard/Cluster: Format Functions
internal/util/format.go,internal/difc/violations.go,internal/config/validation_errors.go,internal/config/validation_schema.gointernal/util/format.gohandles generic formatting (session IDs, durations); domain-specific formatters stay with their domain.Cluster: HTTP Response Writing
internal/httputil/response_writer.go(base),internal/server/response_writer.go(extended),internal/middleware/content_rewrite.goCluster: Context Key Management
internal/guard/context.goguard/context.gomanages DIFC-specific context keys (difc-agent-id,difc-request-state). Its package comment explains the intentional split frominternal/auth. Acceptable as-is, though the file could be renameddifc_context.gofor clarity.Refactoring Recommendations
Priority 1: Quick Wins (< 1 hour each)
Merge
internal/mcpresultintointernal/mcp/tool_result.goNormalizeContentItemsandExtractTextContentRename
MountFormatβMountPathininternal/config/validation_rules.gomountValidationErrorRename
internal/guard/context.goβinternal/guard/difc_context.goPriority 2: Medium Impact (2β4 hours)
Move
proxyForcePublicReposIfNeededfrominternal/cmd/proxy.gotointernal/config/Evaluate merging
internal/jqutilintointernal/middlewareinternal/config) imports jqutilSecureCompileOptsfrom middleware insteadPriority 3: Longer-term (assess before acting)
buildDIFCSingleItemFilteredErrorandbuildDIFCFilteredNoticefrominternal/server/difc_log.gotointernal/difc/violations.goImplementation Checklist
NormalizeContentItems/ExtractTextContentfrominternal/mcpresultβinternal/mcp/tool_result.goMountFormatβMountPathininternal/config/validation_rules.gointernal/guard/context.goβinternal/guard/difc_context.goproxyForcePublicReposIfNeededfrominternal/cmd/proxy.goβinternal/config/guard_policy_resolve.gointernal/jqutilmerge intointernal/middlewaremake test-allafter each changeAnalysis Metadata
BaseResponseWriterembedding is intentional, not duplication)Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.