flipped-aurora/gin-vue-admin · error
参数错误:generatedFiles 必须是JSON字符串
Error message
参数错误:generatedFiles 必须是JSON字符串
What it means
'generatedFiles' must be a string whose contents are a JSON array of file paths. Handle asserts generatedFilesData.(string); if the argument is an array, object, number, bool or nil (e.g. the client sent the array directly instead of a JSON-encoded string), this error is returned before json.Unmarshal is attempted.
Source
Thrown at server/mcp/gva_review.go:81
userRequirementData, ok := request.GetArguments()["userRequirement"]
if !ok {
return nil, errors.New("参数错误:userRequirement 必须提供")
}
userRequirement, ok := userRequirementData.(string)
if !ok {
return nil, errors.New("参数错误:userRequirement 必须是字符串类型")
}
// 获取生成的文件列表
generatedFilesData, ok := request.GetArguments()["generatedFiles"]
if !ok {
return nil, errors.New("参数错误:generatedFiles 必须提供")
}
generatedFilesStr, ok := generatedFilesData.(string)
if !ok {
return nil, errors.New("参数错误:generatedFiles 必须是JSON字符串")
}
// 解析JSON字符串为字符串数组
var generatedFiles []string
err := json.Unmarshal([]byte(generatedFilesStr), &generatedFiles)
if err != nil {
return nil, fmt.Errorf("解析generatedFiles失败: %v", err)
}
if len(generatedFiles) == 0 {
return nil, errors.New("参数错误:generatedFiles 不能为空")
}
// 直接生成调整提示,不进行复杂分析
adjustmentPrompt := g.generateAdjustmentPrompt(userRequirement, generatedFiles)
// 构建简化的审查详情
reviewDetails := fmt.Sprintf("📋 **代码审查报告**\n\n **用户原始需求:**\n%s\n\n **已生成文件数量:** %d\n\n **建议进行代码优化和完善**", userRequirement, len(generatedFiles))View on GitHub (pinned to 3136500ef3)
Solutions
- JSON-encode the array into a string on the client: json.Marshal(files) then pass the resulting string.
- Confirm the argument's JSON type is string, not array, in the outgoing payload.
- Update client code or generated tool bindings to match the current schema.
- If using a dynamic map, cast the array to its JSON string representation before assigning the argument.
Example fix
// before (Go client)
args["generatedFiles"] = []string{"server/api/user.go"}
// after
b, _ := json.Marshal([]string{"server/api/user.go"})
args["generatedFiles"] = string(b) Defensive patterns
Strategy: type-guard
Validate before calling
raw, ok := args["generatedFiles"].(string)
if !ok {
return errors.New("generatedFiles must be a string containing a JSON array")
}
var files []string
if err := json.Unmarshal([]byte(raw), &files); err != nil {
return fmt.Errorf("generatedFiles is not valid JSON array: %w", err)
} Type guard
func isJSONString(v any) bool {
s, ok := v.(string)
if !ok {
return false
}
var arr []string
return json.Unmarshal([]byte(s), &arr) == nil
} Prevention
- Always json.Marshal([]string{...}) the file list before placing it in the arguments.
- Remember MCP maps carry loosely typed values: pass strings for string-typed inputs.
- Add a unit test for the client helper that encodes generatedFiles.
When it happens
Trigger: Calling gva_review with {"generatedFiles": ["a.go", "b.go"]} (raw array) instead of {"generatedFiles": "[\"a.go\",\"b.go\"]"} (string containing JSON).
Common situations: Caller assumes the tool accepts native arrays; JSON serialization double-encoding confusion; clients built from an outdated tool schema that described generatedFiles as array type.
Related errors
- 参数错误:userRequirement 必须是字符串类型
- 解析执行计划失败: %v
- 解析执行计划失败: %v 请确保ExecutionPlan格式正确,参考工具描述中的结构体格式要求
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
- 未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/f7fdb6c218847d1b.
Report an issue: GitHub.