Problem
pkg/workflow/mcp_scripts_parser.go contains two functions — parseMCPScriptsMap (lines 72–191) and the inner loop of (*Compiler).mergeMCPScripts (lines 259–357) — that both implement identical logic for parsing a single MCP script tool config from a map[string]any.
The duplicated block covers:
- Description parsing
- Inputs / params parsing (type, description, required, default)
- Script / run / py / go fields
- Env map parsing
- Timeout parsing (int, uint64, float64, string cases)
If a new field is added to MCPScriptToolConfig, developers must remember to update both sites. Past evidence: alert comments #413 and #414 for the uint64 overflow fix were applied at both sites with different numbers, suggesting they were patched separately.
Recommendation
Extract a private helper:
func parseMCPScriptToolConfig(toolName string, toolMap map[string]any) *MCPScriptToolConfig {
toolConfig := &MCPScriptToolConfig{
Name: toolName,
Inputs: make(map[string]*MCPScriptParam),
Env: make(map[string]string),
Timeout: 60,
}
// ... shared parsing logic ...
return toolConfig
}
Then replace the duplicated blocks in both parseMCPScriptsMap and mergeMCPScripts with a call to this helper.
Impact
- Severity: Medium
- Affected file:
pkg/workflow/mcp_scripts_parser.go
- Risk: Without this refactor, future
MCPScriptToolConfig field additions require two separate edits and tests, increasing the chance of divergence.
Validation
Estimated Effort: Small
Generated by Sergo - Serena Go Expert · ● 475.4K · ◷
Problem
pkg/workflow/mcp_scripts_parser.gocontains two functions —parseMCPScriptsMap(lines 72–191) and the inner loop of(*Compiler).mergeMCPScripts(lines 259–357) — that both implement identical logic for parsing a single MCP script tool config from amap[string]any.The duplicated block covers:
If a new field is added to
MCPScriptToolConfig, developers must remember to update both sites. Past evidence: alert comments#413and#414for theuint64overflow fix were applied at both sites with different numbers, suggesting they were patched separately.Recommendation
Extract a private helper:
Then replace the duplicated blocks in both
parseMCPScriptsMapandmergeMCPScriptswith a call to this helper.Impact
pkg/workflow/mcp_scripts_parser.goMCPScriptToolConfigfield additions require two separate edits and tests, increasing the chance of divergence.Validation
TestParseMCPScripts*andTestMergeMCPScripts*tests pass unchangedswitchremains in production codeEstimated Effort: Small