googleapis/mcp-toolbox · error
invalid parameter type, expected array of type string
Error message
invalid parameter type, expected array of type string
What it means
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.
Source
Thrown at internal/util/parameters/parameters.go:261
}
return paramValues, nil
}
// helper function to convert a string array parameter to a comma separated string
func ConvertArrayParamToString(param any) (string, error) {
switch v := param.(type) {
case []any:
var stringValues []string
for _, item := range v {
stringVal, ok := item.(string)
if !ok {
return "", fmt.Errorf("templateParameter only supports string arrays")
}
stringValues = append(stringValues, stringVal)
}
return strings.Join(stringValues, ", "), nil
default:
return "", fmt.Errorf("invalid parameter type, expected array of type string")
}
}
// GetParams return the ParamValues that are associated with the Parameters.
func GetParams(params Parameters, paramValuesMap map[string]any) (ParamValues, error) {
resultParamValues := make(ParamValues, 0)
for _, p := range params {
k := p.GetName()
v, ok := paramValuesMap[k]
if !ok {
return nil, fmt.Errorf("missing parameter %s", k)
}
resultParamValues = append(resultParamValues, ParamValue{Name: k, Value: v})
}
return resultParamValues, nil
}
func ResolveTemplateParams(templateParams Parameters, originalStatement string, paramsMap map[string]any) (string, error) {View on GitHub (pinned to 8cc6e09de2)
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.
Example fix
# before (helper on a scalar)
SELECT * FROM t WHERE name IN ({{array .name}})
# after (scalar rendered directly)
SELECT * FROM t WHERE name = {{.name}} Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := v.([]any); !ok {
return fmt.Errorf("%q is not an array; {{array}} requires an array value", name)
} Type guard
func isArray(v any) bool {
_, ok := v.([]any)
return ok
} Try / catch
out, err := params.ConvertArrayParamToString(v)
if err != nil && strings.Contains(err.Error(), "invalid parameter type") {
// render scalar directly instead
return fmt.Sprintf("%v", v), nil
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- templateParameter only supports string arrays
- error embedding parameters: %w
- unable to bind: %w
- 'model' must be a string, got %T
- 'explore' must be a string, got %T
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/4ce043a3835c1be3.
Report an issue: GitHub.