Skip to content

[duplicate-code] 🔍 Duplicate Code Detected: Workflow MCP Config Loading #2826

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: Workflow MCP Config Loading

Analysis of commit 1782cd3

Assignee: @copilot

Summary

Repeated logic for loading a workflow file, parsing frontmatter, and extracting MCP configurations appears in both the workflow listing and tool listing commands. The shared steps diverge only after the MCP configs are loaded, making this a good candidate for a shared helper.

Duplication Details

Pattern: Workflow MCP configuration loader

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • pkg/cli/mcp_list.go (lines 24-69)
    • pkg/cli/mcp_list_tools.go (lines 29-74)
  • Code Sample:
    content, err := os.ReadFile(workflowPath)
    if err != nil {
        return fmt.Errorf("failed to read workflow file: %w", err)
    }
    
    workflowData, err := parser.ExtractFrontmatterFromContent(string(content))
    if err != nil {
        return fmt.Errorf("failed to parse workflow file: %w", err)
    }
    
    mcpConfigs, err := parser.ExtractMCPConfigurations(workflowData.Frontmatter, filter)
    if err != nil {
        return fmt.Errorf("failed to extract MCP configurations: %w", err)
    }

Impact Analysis

  • Maintainability: Changes to how MCP configs are loaded must be applied in multiple places, increasing risk of divergence.
  • Bug Risk: Future fixes (e.g., validation, logging, filtering tweaks) could be missed in one function, yielding inconsistent CLI behaviour.
  • Code Bloat: Duplicated control flow inflates the command code and obscures the functional differences.

Refactoring Recommendations

  1. Extract shared loader helper

    • Extract a function like loadWorkflowMCPConfigs(path, filter) (*parser.WorkflowData, []parser.MCPServerConfig, error) into a shared CLI utility.
    • Estimated effort: 1-2 hours
    • Benefits: Centralises error handling, enforces consistent behaviour, simplifies command code.
  2. Share verbose logging support

    • Move verbose logging setup (info/warning messages) into the helper so both commands benefit from future logging improvements automatically.
    • Estimated effort: <1 hour
    • Benefits: Keeps CLI UX consistent and reduces duplicated logging strings.

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: 1782cd3
  • Analysis Date: 2025-10-30 21:09:50Z

AI generated by Duplicate Code Detector

Metadata

Metadata

Assignees

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