{"record":{"id":"f1f9e8fd2f305a53","repo":"googleapis/mcp-toolbox","slug":"expected-item-at-index-d-to-be-integer-got-t","errorCode":null,"errorMessage":"expected item at index %d to be integer, got %T","messagePattern":"expected item at index (.+?) to be integer, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/common.go","lineNumber":43,"sourceCode":"func ConvertAnySliceToTyped(s []any, itemType string) (any, error) {\n\tvar typedSlice any\n\tswitch itemType {\n\tcase \"string\":\n\t\ttempSlice := make([]string, len(s))\n\t\tfor j, item := range s {\n\t\t\ts, ok := item.(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"expected item at index %d to be string, got %T\", j, item)\n\t\t\t}\n\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)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/common.go#L25-L61","documentation":"ConvertAnySliceToTyped converts a []any into []int64 when itemType is \"integer\". Each element must be an `int` (Go native); if any element is not an int (e.g. float64 from JSON, or a string), the function aborts with this error naming the failing index.","triggerScenarios":"Passing a slice containing float64, string, or bool values to ConvertAnySliceToTyped with itemType=\"integer\", e.g. JSON-decoded arrays where numbers are float64, or clients sending quoted numbers [\"1\",\"2\"].","commonSituations":"JSON unmarshalling makes all numbers float64, so integer array params fail; LLM sends \"5\" instead of 5; mixed-type arrays generated by an agent.","solutions":["Ensure the input slice holds Go `int` values before calling, or pre-convert with a normalization loop","If the source is JSON-decoded data, convert float64 elements (whole numbers) to int first","Change the declared parameter type to 'float' if decimals are possible","Have clients send unquoted integer literals in the tool call arguments"],"exampleFix":"// before\nConvertAnySliceToTyped([]any{float64(1), float64(2)}, \"integer\") // fails: float64 not int\n// after\nConvertAnySliceToTyped([]any{1, 2}, \"integer\")","handlingStrategy":"type-guard","validationCode":"func allInts(v []any) bool {\n    for _, item := range v {\n        if _, ok := item.(int); !ok {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func isIntArray(v []any) bool {\n    for _, item := range v {\n        switch item.(type) {\n        case int, int64:\n        default:\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"typed, err := ConvertAnySliceToTyped(s, \"integer\")\nif err != nil {\n    return nil, fmt.Errorf(\"invalid integer array parameter: %w\", err)\n}","preventionTips":["Remember JSON decoding yields float64; convert to int before passing","Normalize numeric strings (\"5\") to ints at the ingestion boundary","Declare the schema element type as 'integer' so clients send real integers"],"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"}