-
Notifications
You must be signed in to change notification settings - Fork 304
Description
Overview
Semantic duplicate-code analysis found a high-impact structural duplication pattern in engine-specific MCP configuration rendering logic. Multiple engines implement near-identical RenderMCPConfig bodies with only small option/function differences.
This exceeds the duplication threshold (>10 lines and 3+ similar occurrences) and increases maintenance risk for MCP feature updates.
Critical Information
- Severity: Medium
- Pattern type: Structural duplication
- Occurrences: 4 major implementations with large shared structure
- Primary files:
pkg/workflow/claude_mcp.gopkg/workflow/gemini_mcp.gopkg/workflow/copilot_mcp.gopkg/workflow/codex_mcp.go
- Shared call site impact:
pkg/workflow/mcp_setup_generator.go:772
Duplication Details
Pattern
Each engine method builds a renderer closure, config path/gateway options, and a mostly repeated MCPToolRenderers map wiring (RenderGitHub, RenderPlaywright, RenderSerena, RenderAgenticWorkflows, RenderSafeOutputs, RenderMCPScripts, RenderWebFetch, custom render callback).
Representative locations
pkg/workflow/claude_mcp.go:12pkg/workflow/gemini_mcp.go:12pkg/workflow/copilot_mcp.go:12pkg/workflow/codex_mcp.go:13
Example repeated block shape
createRenderer := func(isLast bool) *MCPConfigRendererUnified {
return NewMCPConfigRenderer(MCPRendererOptions{...})
}
return RenderJSONMCPConfig(yaml, tools, mcpTools, workflowData, JSONMCPConfigOptions{
ConfigPath: ...,
GatewayConfig: ...,
Renderers: MCPToolRenderers{
RenderGitHub: ...,
RenderPlaywright: ...,
RenderSerena: ...,
RenderAgenticWorkflows: ...,
RenderSafeOutputs: ...,
RenderMCPScripts: ...,
RenderWebFetch: ...,
RenderCustomMCPConfig: ...,
},
})Impact Analysis
- Maintainability: MCP renderer changes require synchronized edits across several files.
- Bug risk: Inconsistent behavior can be introduced when one engine is updated and others are missed.
- Code bloat: Large repeated setup/mapping code obscures engine-specific differences.
Recommendations
- Extract a shared helper to build
JSONMCPConfigOptionsfrom an engine-specific config struct. - Isolate per-engine variability into small callbacks/flags (config path, copilot fields, custom renderer function).
- Keep engine files focused on deltas; delegate common renderer map wiring to one shared function.
Implementation Checklist
- Define shared options builder for engine MCP rendering
- Refactor Claude/Gemini/Copilot/Codex to use shared builder
- Preserve engine-specific behavior with targeted unit tests
- Verify generated YAML/TOML output parity for each engine
Analysis Metadata
- Detection method: Serena semantic symbol analysis + pattern comparison
- Commit analyzed:
0de8141017e235fecb2892b6ce4123728564462c - Workflow run: §23177760953
- Analysis date: 2026-03-17 UTC
Generated by Duplicate Code Detector · ◷
Warning
⚠️ Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
ab.chatgpt.com
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
network:
allowed:
- defaults
- "ab.chatgpt.com"See Network Configuration for more information.