{"record":{"id":"6eb62bec62745665","repo":"googleapis/mcp-toolbox","slug":"expected-item-at-index-d-to-be-float-got-t","errorCode":null,"errorMessage":"expected item at index %d to be float, got %T","messagePattern":"expected item at index (.+?) to be float, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/common.go","lineNumber":53,"sourceCode":"\t\t\ttempSlice[j] = s\n\t\t}\n\t\ttypedSlice = tempSlice\n\tcase \"integer\":\n\t\ttempSlice := make([]int64, len(s))\n\t\tfor j, item := range s {\n\t\t\ti, ok := item.(int)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"expected item at index %d to be integer, got %T\", j, item)\n\t\t\t}\n\t\t\ttempSlice[j] = int64(i)\n\t\t}\n\t\ttypedSlice = tempSlice\n\tcase \"float\":\n\t\ttempSlice := make([]float64, len(s))\n\t\tfor j, item := range s {\n\t\t\tf, ok := item.(float64)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"expected item at index %d to be float, got %T\", j, item)\n\t\t\t}\n\t\t\ttempSlice[j] = f\n\t\t}\n\t\ttypedSlice = tempSlice\n\tcase \"boolean\":\n\t\ttempSlice := make([]bool, len(s))\n\t\tfor j, item := range s {\n\t\t\tb, ok := item.(bool)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"expected item at index %d to be boolean, got %T\", j, item)\n\t\t\t}\n\t\t\ttempSlice[j] = b\n\t\t}\n\t\ttypedSlice = tempSlice\n\t}\n\treturn typedSlice, nil\n}\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/common.go#L35-L71","documentation":"ConvertAnySliceToTyped converts a []any into []float64 when itemType is \"float\". Every element must be a float64; otherwise the function returns this error identifying the index of the non-float element.","triggerScenarios":"Passing a slice containing ints, strings, or bools with itemType=\"float\", e.g. []any{1.5, 2} where 2 is an int literal, or a client sending \"3.14\" as a string.","commonSituations":"Go code building arrays with int literals instead of float literals; agents sending numeric strings; configs mixing integers and decimals in one array.","solutions":["Convert all elements to float64 before calling (e.g. float64(i) for ints)","Fix client input so all numbers carry decimal form or match the schema type","Declare the parameter as 'integer' if fractional values are never expected","Log the offending index (from the message) and correct the producer of that element"],"exampleFix":"// before\nConvertAnySliceToTyped([]any{1.5, 2}, \"float\") // fails: 2 is int\n// after\nConvertAnySliceToTyped([]any{1.5, 2.0}, \"float\")","handlingStrategy":"type-guard","validationCode":"func allFloats(v []any) bool {\n    for _, item := range v {\n        if _, ok := item.(float64); !ok {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func isFloatArray(v []any) bool {\n    for _, item := range v {\n        switch item.(type) {\n        case float64, float32:\n        default:\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"typed, err := ConvertAnySliceToTyped(s, \"float\")\nif err != nil {\n    return nil, fmt.Errorf(\"invalid float array parameter: %w\", err)\n}","preventionTips":["Use float literals (2.0, not 2) when building []any in Go","Parse numeric strings to float64 before templating/conversion","Keep array element types homogeneous"],"tags":["parameters","type-mismatch","arrays"],"backgroundTag":"parameter-type-mismatch","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}