🔍 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
-
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.
-
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
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
🔍 Duplicate Code Detected: Workflow MCP Config Loading
Analysis of commit 1782cd3
Assignee:
@copilotSummary
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
pkg/cli/mcp_list.go(lines 24-69)pkg/cli/mcp_list_tools.go(lines 29-74)Impact Analysis
Refactoring Recommendations
Extract shared loader helper
loadWorkflowMCPConfigs(path, filter) (*parser.WorkflowData, []parser.MCPServerConfig, error)into a shared CLI utility.Share verbose logging support
Implementation Checklist
Analysis Metadata