🔍 Duplicate Code Detected: GitHub MCP Renderer Logic
Analysis of commit 7658c86
Assignee: @copilot
Summary
Rendering the GitHub MCP server configuration is implemented separately in the Copilot, Claude, Codex, and Custom engine files. Each version repeats the same remote/local branching, token precedence, and closing boilerplate with only minor option differences.
Duplication Details
Pattern: Repeated GitHub MCP rendering branches in engine renderers
- Severity: Medium
- Occurrences: 4
- Locations:
pkg/workflow/copilot_engine.go:398
pkg/workflow/claude_engine.go:652
pkg/workflow/codex_engine.go:479
pkg/workflow/custom_engine.go:161
- Code Sample:
githubType := getGitHubType(githubTool)
readOnly := getGitHubReadOnly(githubTool)
toolsets := getGitHubToolsets(githubTool)
yaml.WriteString(" \"github\": {\n")
if githubType == "remote" {
RenderGitHubMCPRemoteConfig(...)
} else {
RenderGitHubMCPDockerConfig(...)
}
if isLast {
yaml.WriteString(" }\n")
} else {
yaml.WriteString(" },\n")
}
Impact Analysis
- Maintainability: Any change to GitHub MCP rendering rules must be replicated four times, increasing the chance the engine implementations drift apart.
- Bug Risk: Fixes for token precedence or read-only handling can be missed in one engine, leading to subtle runtime differences.
- Code Bloat: Roughly 150 lines of near-identical logic inflate the workflow package and obscure true engine-specific behavior.
Refactoring Recommendations
-
Extract a shared GitHub MCP rendering helper
- Centralize the remote/local branching and token resolution in
engine_helpers.go (or a new helper) that accepts formatting options (JSON vs TOML, allowed tool handling, env passthrough).
- Estimated effort: Medium (4–6h)
- Benefits: Single source of truth, easier future fixes, consistent behavior across engines.
-
Model GitHub MCP config as a shared struct
- Populate a
GitHubMCPConfig struct once per engine and pass it to format-specific writers (JSON/TOML) to eliminate repeated yaml.WriteString sequences.
- Estimated effort: Medium (4h)
- Benefits: Clear separation between data gathering and rendering, unlocks unit tests on shared logic.
Implementation Checklist
Analysis Metadata
- Analyzed Files: 4
- Detection Method: Serena semantic code analysis
- Commit: 7658c86
- Analysis Date: 2025-10-24T21:09:47Z
AI generated by Duplicate Code Detector
🔍 Duplicate Code Detected: GitHub MCP Renderer Logic
Analysis of commit 7658c86
Assignee:
@copilotSummary
Rendering the GitHub MCP server configuration is implemented separately in the Copilot, Claude, Codex, and Custom engine files. Each version repeats the same remote/local branching, token precedence, and closing boilerplate with only minor option differences.
Duplication Details
Pattern: Repeated GitHub MCP rendering branches in engine renderers
pkg/workflow/copilot_engine.go:398pkg/workflow/claude_engine.go:652pkg/workflow/codex_engine.go:479pkg/workflow/custom_engine.go:161Impact Analysis
Refactoring Recommendations
Extract a shared GitHub MCP rendering helper
engine_helpers.go(or a new helper) that accepts formatting options (JSON vs TOML, allowed tool handling, env passthrough).Model GitHub MCP config as a shared struct
GitHubMCPConfigstruct once per engine and pass it to format-specific writers (JSON/TOML) to eliminate repeatedyaml.WriteStringsequences.Implementation Checklist
Analysis Metadata