Skip to content

refactor: extract parseMCPScriptToolConfig helper to remove duplication in mcp_scripts_parser.go #28796

@github-actions

Description

@github-actions

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

  • All existing TestParseMCPScripts* and TestMergeMCPScripts* tests pass unchanged
  • No behavioural change: only structural consolidation
  • Grep confirms only one copy of the timeout switch remains in production code

Estimated Effort: Small

Generated by Sergo - Serena Go Expert · ● 475.4K ·

  • expires on May 4, 2026, 8:44 PM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

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