Skip to content

Duplicate Code: JSON MCP RenderMCPConfig scaffolding across engine modules #21900

Description

@github-actions

Overview

The latest commit (f3c7b792f95f8b3e6178f8612109832ca13dc627) contains repeated JSON MCP configuration scaffolding across engine implementations in pkg/workflow. The duplicated block is large enough (>10 lines) and appears in multiple engine-specific files with only small callback/path differences.

Critical Information

  • Severity: Medium
  • Pattern type: Structural duplication (copy-paste with minor variations)
  • Occurrences: 3 primary occurrences
  • Impacted area: MCP configuration rendering for CLI engines

Duplication Details

Pattern: Engine RenderMCPConfig setup repetition

  • pkg/workflow/claude_mcp.go:12
  • pkg/workflow/gemini_mcp.go:12
  • pkg/workflow/copilot_mcp.go:12

The methods repeat the same sequence:

  1. Log render start
  2. Construct JSON renderer factory
  3. Build gateway config with buildMCPGatewayConfig(workflowData)
  4. Build standard JSON renderers
  5. Call RenderJSONMCPConfig(...)
Representative duplicated block
createRenderer := buildMCPRendererFactory(workflowData, "json", false, false)

return RenderJSONMCPConfig(yaml, tools, mcpTools, workflowData, JSONMCPConfigOptions{
    ConfigPath:    "/tmp/gh-aw/mcp-config/mcp-servers.json",
    GatewayConfig: buildMCPGatewayConfig(workflowData),
    Renderers: buildStandardJSONMCPRenderers(workflowData, createRenderer, false, func(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool) error {
        // engine-specific callback only
        return ...
    }),
})

Impact Analysis

  • Maintainability: Changes to shared JSON MCP behavior must be repeated in multiple files, increasing drift risk.
  • Bug risk: Engine-specific files can diverge subtly when only one file is updated during future feature work.
  • Code bloat: Repeated setup logic reduces signal-to-noise in engine modules.

Refactoring Recommendations

  1. Extract a shared helper for JSON MCP rendering options
  • Suggested location: pkg/workflow/mcp_renderer_helpers.go or pkg/workflow/mcp_engine_shared.go
  • Helper input: config path, copilot flags, callback, optional tool filter
  • Helper output: unified RenderJSONMCPConfig(...) invocation
  1. Keep only engine-specific concerns in engine files
  • Claude/Gemini: callback function and logger message
  • Copilot: pre-step (mkdir) and FilterTool

Implementation Checklist

  • Introduce shared helper for JSON MCP config scaffolding
  • Update claude_mcp.go, gemini_mcp.go, and copilot_mcp.go to use helper
  • Validate generated MCP config output parity for all engines
  • Add/adjust focused unit tests around helper behavior

Analysis Metadata

  • Analyzed scope: pkg/**/*.go (non-test files in changed commit)
  • Deep semantic review focus: MCP gateway/config rendering paths
  • Detection method: Serena symbol/body comparison + targeted pattern search
  • Workflow run: §23328418561
  • Analysis date: 2026-03-20 UTC

References:

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.

Generated by Duplicate Code Detector ·

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions