-
Notifications
You must be signed in to change notification settings - Fork 295
Closed
Description
🔍 Duplicate Code Detected: GitHub MCP Remote Config Rendering
Analysis of commit 82e9c3e
Assignee: @copilot
Summary
The GitHub MCP remote configuration block is duplicated between the Claude and Copilot engine renderers. Both functions build the same header map and YAML block with only minor token differences, making future fixes error-prone.
Duplication Details
Pattern: Repeated GitHub MCP remote header rendering logic
- Severity: Medium
- Occurrences: 2
- Locations:
pkg/workflow/claude_engine.go:652pkg/workflow/copilot_engine.go:402
- Code Sample:
// Remote mode - use hosted GitHub MCP server yaml.WriteString(" \"type\": \"http\",\n") yaml.WriteString(" \"url\": \"(redacted)",\n") yaml.WriteString(" \"headers\": {\n") headers := make(map[string]string) headers["Authorization"] = fmt.Sprintf("Bearer %s", effectiveToken) if readOnly { headers["X-MCP-Readonly"] = "true" } if toolsets != "" { headers["X-MCP-Toolsets"] = toolsets } writeHeadersToYAML(yaml, headers, " ") yaml.WriteString(" }\n")
Impact Analysis
- Maintainability: Two nearly identical blocks must be kept in sync; fixes to headers or indentation must be applied twice.
- Bug Risk: Minor differences (e.g., Authorization value) already exist, increasing the chance of inconsistent behavior across engines.
- Code Bloat: Adds ~15 repeated lines that could live in a single helper.
Refactoring Recommendations
-
Extract Common Helper
- Lift the shared remote-rendering logic into a function (e.g.
renderGitHubMCPRemoteConfig) that accepts token formatting callbacks. - Estimated effort: 1-2 hours.
- Benefits: Single source of truth, easier updates.
- Lift the shared remote-rendering logic into a function (e.g.
-
Parameterize Authorization Value
- Pass the differing Authorization string as a parameter so both engines can reuse the helper.
- Benefits: Eliminates divergence and clarifies intentional differences.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 2
- Detection Method: Serena semantic code analysis
- Commit: 82e9c3e
- Analysis Date: 2025-10-23
AI generated by Duplicate Code Detector
Reactions are currently unavailable