{"record":{"id":"bbabb7f9ead6414e","repo":"googleapis/mcp-toolbox","slug":"expected-item-at-index-d-to-be-string-got-t","errorCode":null,"errorMessage":"expected item at index %d to be string, got %T","messagePattern":"expected item at index (.+?) to be string, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/common.go","lineNumber":33,"sourceCode":"package parameters\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"text/template\"\n)\n\n// ConvertAnySliceToTyped a []any to typed slice ([]string, []int, []float etc.)\nfunc 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)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/common.go#L15-L51","documentation":"ConvertAnySliceToTyped converts a []any parameter into a typed Go slice (string, int64, float64, or bool) based on the itemType argument. This error is returned when an element of the input slice cannot be asserted to the requested type, i.e. the array passed by the tool caller contained a value of the wrong kind at position j.","triggerScenarios":"Calling ConvertAnySliceToTyped (directly or via ProcessQueryArgs/ParseDICOMSearchParameters/buildQueryParameters/InvokeSearchCatalog) with itemType=\"string\" while the slice contains e.g. a float64 or bool, typically because a client sent [123] for a string array parameter.","commonSituations":"LLM-generated tool arguments with heterogeneous arrays; clients sending numbers for string array params (e.g. list of IDs as integers); YAML/JSON configs where quoted values lost their quotes; version changes in how a datasource parses array parameters.","solutions":["Fix the client/tool input so every element of the array matches the declared parameter type (strings for 'string', integers for 'integer', etc.)","Check the tool's parameter schema (manifest) and send the array with the correct element type","If values are integers arriving as floats (JSON numbers), convert or declare the parameter as 'integer'/'float' instead of 'string'","Wrap the call and surface the index from the error message to identify the offending array element"],"exampleFix":"// before\nConvertAnySliceToTyped([]any{\"a\", 42}, \"string\") // fails at index 1\n// after\nConvertAnySliceToTyped([]any{\"a\", \"42\"}, \"string\")","handlingStrategy":"type-guard","validationCode":"func allStrings(v []any) bool {\n    for _, item := range v {\n        if _, ok := item.(string); !ok {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func isStringArray(v []any) bool {\n    ok := true\n    for _, item := range v {\n        _, ok = item.(string)\n        if !ok {\n            return false\n        }\n    }\n    return ok\n}","tryCatchPattern":"typed, err := ConvertAnySliceToTyped(s, \"string\")\nif err != nil {\n    // err names the offending index; return a 400-style client error\n    return nil, fmt.Errorf(\"invalid string array parameter: %w\", err)\n}","preventionTips":["Validate tool inputs against the parameter manifest/schema before invocation","Send JSON arrays whose element types match the declared schema exactly","Quote string values in configs so parsers don't coerce them to numbers"],"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"}