Part of duplicate code analysis: #4773
Summary
internal/mcp/schema.go's NormalizeInputSchema function contains two identical 4-line blocks that shallow-copy a map[string]interface{} before adding a key. This inline copy-before-mutate pattern is repeated twice and could be extracted into a single helper.
Duplication Details
Pattern: Inline map shallow-copy before adding a key
- Severity: Low
- Occurrences: 2 (within the same function)
- Location:
internal/mcp/schema.go (lines 39–44 and 74–79)
Duplicated code:
// Lines 39–44
normalized := make(map[string]interface{})
for k, v := range schema {
normalized[k] = v
}
normalized["type"] = "object"
return normalized
// Lines 74–79
normalized := make(map[string]interface{})
for k, v := range schema {
normalized[k] = v
}
normalized["properties"] = map[string]interface{}{}
return normalized
Impact Analysis
- Maintainability: Minor — if the copy logic needs to change (e.g., to use
maps.Clone from Go 1.21), it must be changed in two places
- Bug Risk: Low, but divergence between the two blocks is possible
- Code Bloat: 8 lines of boilerplate that could be 2 lines
Refactoring Recommendations
-
Extract a copySchemaWithKey helper (or use maps.Clone from golang.org/x/exp/maps / Go 1.21 stdlib):
// copySchemaWithKey returns a shallow copy of schema with the given key set.
func copySchemaWithKey(schema map[string]interface{}, key string, value interface{}) map[string]interface{} {
normalized := make(map[string]interface{}, len(schema)+1)
for k, v := range schema {
normalized[k] = v
}
normalized[key] = value
return normalized
}
Then replace both blocks:
return copySchemaWithKey(schema, "type", "object")
// ...
return copySchemaWithKey(schema, "properties", map[string]interface{}{})
Estimated effort: 30 minutes.
Implementation Checklist
Parent Issue
See parent analysis report: #4773
Related to #4773
Generated by Duplicate Code Detector · ● 1.4M · ◷
Part of duplicate code analysis: #4773
Summary
internal/mcp/schema.go'sNormalizeInputSchemafunction contains two identical 4-line blocks that shallow-copy amap[string]interface{}before adding a key. This inline copy-before-mutate pattern is repeated twice and could be extracted into a single helper.Duplication Details
Pattern: Inline map shallow-copy before adding a key
internal/mcp/schema.go(lines 39–44 and 74–79)Duplicated code:
Impact Analysis
maps.Clonefrom Go 1.21), it must be changed in two placesRefactoring Recommendations
Extract a
copySchemaWithKeyhelper (or usemaps.Clonefromgolang.org/x/exp/maps/ Go 1.21 stdlib):Then replace both blocks:
Estimated effort: 30 minutes.
Implementation Checklist
copySchemaWithKeyhelper (or usemaps.Clone)make testto verify no regressionsParent Issue
See parent analysis report: #4773
Related to #4773