{"record":{"id":"f7fdb6c218847d1b","repo":"flipped-aurora/gin-vue-admin","slug":"generatedfiles-json","errorCode":null,"errorMessage":"参数错误：generatedFiles 必须是JSON字符串","messagePattern":"参数错误：generatedFiles 必须是JSON字符串","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/gva_review.go","lineNumber":81,"sourceCode":"\tuserRequirementData, ok := request.GetArguments()[\"userRequirement\"]\n\tif !ok {\n\t\treturn nil, errors.New(\"参数错误：userRequirement 必须提供\")\n\t}\n\n\tuserRequirement, ok := userRequirementData.(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"参数错误：userRequirement 必须是字符串类型\")\n\t}\n\n\t// 获取生成的文件列表\n\tgeneratedFilesData, ok := request.GetArguments()[\"generatedFiles\"]\n\tif !ok {\n\t\treturn nil, errors.New(\"参数错误：generatedFiles 必须提供\")\n\t}\n\n\tgeneratedFilesStr, ok := generatedFilesData.(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"参数错误：generatedFiles 必须是JSON字符串\")\n\t}\n\n\t// 解析JSON字符串为字符串数组\n\tvar generatedFiles []string\n\terr := json.Unmarshal([]byte(generatedFilesStr), &generatedFiles)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"解析generatedFiles失败: %v\", err)\n\t}\n\n\tif len(generatedFiles) == 0 {\n\t\treturn nil, errors.New(\"参数错误：generatedFiles 不能为空\")\n\t}\n\n\t// 直接生成调整提示，不进行复杂分析\n\tadjustmentPrompt := g.generateAdjustmentPrompt(userRequirement, generatedFiles)\n\n\t// 构建简化的审查详情\n\treviewDetails := fmt.Sprintf(\"📋 **代码审查报告**\\n\\n **用户原始需求：**\\n%s\\n\\n **已生成文件数量：** %d\\n\\n **建议进行代码优化和完善**\", userRequirement, len(generatedFiles))","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/gva_review.go#L63-L99","documentation":"'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.","triggerScenarios":"Calling gva_review with {\"generatedFiles\": [\"a.go\", \"b.go\"]} (raw array) instead of {\"generatedFiles\": \"[\\\"a.go\\\",\\\"b.go\\\"]\"} (string containing JSON).","commonSituations":"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.","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."],"exampleFix":"// before (Go client)\nargs[\"generatedFiles\"] = []string{\"server/api/user.go\"}\n// after\nb, _ := json.Marshal([]string{\"server/api/user.go\"})\nargs[\"generatedFiles\"] = string(b)","handlingStrategy":"type-guard","validationCode":"raw, ok := args[\"generatedFiles\"].(string)\nif !ok {\n    return errors.New(\"generatedFiles must be a string containing a JSON array\")\n}\nvar files []string\nif err := json.Unmarshal([]byte(raw), &files); err != nil {\n    return fmt.Errorf(\"generatedFiles is not valid JSON array: %w\", err)\n}","typeGuard":"func isJSONString(v any) bool {\n    s, ok := v.(string)\n    if !ok {\n        return false\n    }\n    var arr []string\n    return json.Unmarshal([]byte(s), &arr) == nil\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["mcp","type-error","json","go"],"backgroundTag":"type-assertion-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}