{"record":{"id":"4ce043a3835c1be3","repo":"googleapis/mcp-toolbox","slug":"invalid-parameter-type-expected-array-of-type-str","errorCode":null,"errorMessage":"invalid parameter type, expected array of type string","messagePattern":"invalid parameter type, expected array of type string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/parameters.go","lineNumber":261,"sourceCode":"\t}\n\treturn paramValues, nil\n}\n\n// helper function to convert a string array parameter to a comma separated string\nfunc ConvertArrayParamToString(param any) (string, error) {\n\tswitch v := param.(type) {\n\tcase []any:\n\t\tvar stringValues []string\n\t\tfor _, item := range v {\n\t\t\tstringVal, ok := item.(string)\n\t\t\tif !ok {\n\t\t\t\treturn \"\", fmt.Errorf(\"templateParameter only supports string arrays\")\n\t\t\t}\n\t\t\tstringValues = append(stringValues, stringVal)\n\t\t}\n\t\treturn strings.Join(stringValues, \", \"), nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid parameter type, expected array of type string\")\n\t}\n}\n\n// GetParams return the ParamValues that are associated with the Parameters.\nfunc GetParams(params Parameters, paramValuesMap map[string]any) (ParamValues, error) {\n\tresultParamValues := make(ParamValues, 0)\n\tfor _, p := range params {\n\t\tk := p.GetName()\n\t\tv, ok := paramValuesMap[k]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"missing parameter %s\", k)\n\t\t}\n\t\tresultParamValues = append(resultParamValues, ParamValue{Name: k, Value: v})\n\t}\n\treturn resultParamValues, nil\n}\n\nfunc ResolveTemplateParams(templateParams Parameters, originalStatement string, paramsMap map[string]any) (string, error) {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/parameters.go#L243-L279","documentation":"The default branch of ConvertArrayParamToString rejects any value that is not a []any slice. The {{array}} template helper only accepts arrays; scalars, maps, and nil values hit this error. It signals the helper was applied to a non-array parameter value.","triggerScenarios":"Calling ConvertArrayParamToString (via {{array .param}}) with a string, number, map, or nil value — e.g. {{array .name}} where name is a plain string, or an omitted optional parameter leaving the key nil at render time.","commonSituations":"Template authors applying the array helper to scalar parameters by mistake; clients sending a single value for a parameter declared as an array; missing optional parameters without defaults reaching the helper.","solutions":["Use {{array}} only for array parameters; render scalars with plain {{.param}}.","Ensure callers send a real JSON array (e.g. [\"a\", \"b\"], not \"a\") for array-typed parameters.","Add template conditionals ({{if .param}}...{{end}}) or defaults so nil values never reach the helper.","Align the parameter's declared type in the tool config with what clients actually send."],"exampleFix":"# before (helper on a scalar)\nSELECT * FROM t WHERE name IN ({{array .name}})\n\n# after (scalar rendered directly)\nSELECT * FROM t WHERE name = {{.name}}","handlingStrategy":"type-guard","validationCode":"if _, ok := v.([]any); !ok {\n    return fmt.Errorf(\"%q is not an array; {{array}} requires an array value\", name)\n}","typeGuard":"func isArray(v any) bool {\n    _, ok := v.([]any)\n    return ok\n}","tryCatchPattern":"out, err := params.ConvertArrayParamToString(v)\nif err != nil && strings.Contains(err.Error(), \"invalid parameter type\") {\n    // render scalar directly instead\n    return fmt.Sprintf(\"%v\", v), nil\n}","preventionTips":["Apply {{array}} only to array-typed parameters; use {{.param}} for scalars.","Ensure clients send JSON arrays for array parameters, never bare values.","Give optional parameters defaults so nil never reaches the helper.","Keep declared parameter types aligned with documented client payloads."],"tags":["templates","parameters","type-mismatch"],"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"}