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

  1. JSON-encode the array into a string on the client: json.Marshal(files) then pass the resulting string.
  2. Confirm the argument's JSON type is string, not array, in the outgoing payload.
  3. Update client code or generated tool bindings to match the current schema.
  4. 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

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


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/f7fdb6c218847d1b. Report an issue: GitHub.