{"record":{"id":"620156034cebf0c5","repo":"googleapis/mcp-toolbox","slug":"templateparameter-only-supports-string-arrays","errorCode":null,"errorMessage":"templateParameter only supports string arrays","messagePattern":"templateParameter only supports string arrays","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/parameters.go","lineNumber":255,"sourceCode":"\t\t\t}\n\n\t\t\tformattedVector := formatter(rawVector)\n\t\t\tfinalValue = formattedVector\n\t\t\tparamValues[item.Index].Value = finalValue\n\t\t}\n\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}","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/parameters.go#L237-L273","documentation":"ConvertArrayParamToString is the implementation of the {{array ...}} Go template helper, which joins array parameters into a comma-separated string. When the value is a []any but any element is not a string, it fails with this error. Only arrays whose items are all strings are supported.","triggerScenarios":"Using {{array .param}} in a statement where the parameter's runtime value is an array containing non-string elements — numbers, booleans, nulls, nested objects or arrays, e.g. ids = [1, 2, 3].","commonSituations":"LLM clients sending numeric ID arrays; JSON request bodies with mixed-type arrays; template authors applying the array helper to parameters they assumed were string-typed; schemas declaring 'array' without restricting item type.","solutions":["Coerce elements to strings before invoking the tool (send [\"1\", \"2\"] instead of [1, 2]).","Tighten the parameter schema so items are typed as strings, rejecting mixed arrays earlier.","Remove the {{array}} helper for non-string arrays and use default template rendering or another helper.","Add a client-side check that every element is a string before the call."],"exampleFix":"// before (numeric elements fail)\n{\"ids\": [1, 2, 3]}\n\n// after (string elements)\n{\"ids\": [\"1\", \"2\", \"3\"]}","handlingStrategy":"validation","validationCode":"func isStringArray(v any) bool {\n    arr, ok := v.([]any)\n    if !ok { return false }\n    for _, it := range arr {\n        if _, ok := it.(string); !ok { return false }\n    }\n    return true\n}","typeGuard":"func toStringArray(v any) ([]string, bool) {\n    arr, ok := v.([]any)\n    if !ok { return nil, false }\n    out := make([]string, 0, len(arr))\n    for _, it := range arr {\n        s, ok := it.(string)\n        if !ok { return nil, false }\n        out = append(out, s)\n    }\n    return out, true\n}","tryCatchPattern":"joined, err := params.ConvertArrayParamToString(v)\nif err != nil && strings.Contains(err.Error(), \"only supports string arrays\") {\n    // convert elements to strings or use plain rendering\n    return fallbackRender(v)\n}","preventionTips":["Type array parameters with string items in the tool schema.","Convert numeric IDs to strings at the client boundary.","Document that {{array}} accepts only string arrays.","Add integration tests that pass realistic 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"}