Skip to content

Duplicate Code: MCP gateway converter pipeline repeated across engine adapters #26857

@github-actions

Description

@github-actions

Summary

The recent commit introduces four MCP gateway converter scripts that reimplement the same normalization pipeline (env validation, server filtering, URL rewrite, output stats, secure write) with small format-specific differences.

This is significant structural duplication across 4 files and increases bug-fix drift risk when validation/security behavior changes.

Duplication Details

Pattern: Engine-specific gateway config converters with repeated core flow

  • Severity: Medium
  • Occurrences: 4
  • Locations:
    • actions/setup/js/convert_gateway_config_claude.cjs (lines 42-116)
    • actions/setup/js/convert_gateway_config_copilot.cjs (lines 41-117)
    • actions/setup/js/convert_gateway_config_gemini.cjs (lines 47-139)
    • actions/setup/js/convert_gateway_config_codex.cjs (lines 30-116)

Code sample (shared shape across files):

const gatewayOutput = process.env.MCP_GATEWAY_OUTPUT;
const domain = process.env.MCP_GATEWAY_DOMAIN;
const port = process.env.MCP_GATEWAY_PORT;

if (!gatewayOutput) { ... }
if (!fs.existsSync(gatewayOutput)) { ... }
if (!domain) { ... }
if (!port) { ... }

const cliServers = new Set(JSON.parse(process.env.GH_AW_MCP_CLI_SERVERS || "[]"));
const config = JSON.parse(fs.readFileSync(gatewayOutput, "utf8"));
const servers = ...;
for (const [name, value] of Object.entries(servers)) {
  if (cliServers.has(name)) continue;
  // engine-specific tweak
  // rewrite URL
}
// write output with mode 0o600

Impact Analysis

  • Maintainability: Any change to env validation, filtering, URL rewrite rules, or output hardening must be patched in four places.
  • Bug Risk: Inconsistent behavior between engines is likely over time (especially around required env vars and token-protection comments/write paths).
  • Code Bloat: Repeated conversion scaffolding obscures the actual engine-specific differences.

Refactoring Recommendations

  1. Extract shared conversion pipeline to actions/setup/js/convert_gateway_config_shared.cjs
  • Provide reusable helpers for env validation, config loading, server iteration, URL rewrite, stats, and secure file write.
  • Estimated effort: 4-6 hours.
  • Benefit: Single source of truth for safety-critical behavior.
  1. Keep per-engine adapters thin
  • Each adapter should provide only transform hooks (mutateEntry, buildOutput, outputPath).
  • Estimated effort: 2-3 hours.
  • Benefit: Reduced drift and simpler tests.

Implementation Checklist

  • Extract shared helpers
  • Refactor Claude/Copilot/Gemini/Codex converters to adapters
  • Keep existing behavior and output formats unchanged
  • Update/expand tests to assert parity across engines

Analysis Metadata

  • Analyzed files: 981 changed non-test .go/.cjs files
  • Detection method: semantic/structural comparison + file diffs
  • Commit: 74d8068
  • Analysis date: 2026-04-17 UTC

References:

Warning

⚠️ Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • api.github.com
  • chatgpt.com
  • github.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "api.github.com"
    - "chatgpt.com"
    - "github.com"

See Network Configuration for more information.

Generated by Duplicate Code Detector ·

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions