{"record":{"id":"c5af3c76782cd70b","repo":"googleapis/mcp-toolbox","slug":"expected-item-at-index-d-to-be-boolean-got-t","errorCode":null,"errorMessage":"expected item at index %d to be boolean, got %T","messagePattern":"expected item at index (.+?) to be boolean, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/common.go","lineNumber":63,"sourceCode":"\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\n// convertParamToJSON  is a Go template helper function to convert a parameter to JSON formatted string.\nfunc convertParamToJSON(param any) (string, error) {\n\tjsonData, err := json.Marshal(param)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal param to JSON: %w\", err)\n\t}\n\treturn string(jsonData), nil\n}\n\n// PopulateTemplateWithJSON populate a Go template with a custom `json` array formatter","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/common.go#L45-L81","documentation":"ConvertAnySliceToTyped converts a []any into []bool when itemType is \"boolean\". Each element must be exactly a Go `bool`; anything else (strings \"true\"/\"false\", numbers) triggers this error at the failing index.","triggerScenarios":"Passing []any{\"true\"} or []any{1} with itemType=\"boolean\" — commonly from clients serializing booleans as strings or from agent-generated arguments.","commonSituations":"Form/query string inputs where booleans arrive as strings; YAML configs with unquoted yes/no; LLM emitting \"true\" instead of true.","solutions":["Have callers send native JSON booleans (true/false), not strings","Pre-normalize string flags to bool (parse \"true\"/\"1\" etc.) before calling","If string flags are unavoidable, use itemType=\"string\" and convert downstream","Check the tool manifest schema to confirm the array element type is boolean"],"exampleFix":"// before\nConvertAnySliceToTyped([]any{\"true\"}, \"boolean\") // fails\n// after\nConvertAnySliceToTyped([]any{true}, \"boolean\")","handlingStrategy":"type-guard","validationCode":"func allBools(v []any) bool {\n    for _, item := range v {\n        if _, ok := item.(bool); !ok {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func isBoolArray(v []any) bool {\n    for _, item := range v {\n        if _, ok := item.(bool); !ok {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"typed, err := ConvertAnySliceToTyped(s, \"boolean\")\nif err != nil {\n    return nil, fmt.Errorf(\"invalid boolean array parameter: %w\", err)\n}","preventionTips":["Send native JSON booleans, not \"true\"/\"1\" strings","Parse string flags with strconv.ParseBool at the boundary if strings are unavoidable","Validate against the manifest schema before invoking"],"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"}