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

  1. Use {{array}} only for array parameters; render scalars with plain {{.param}}.
  2. Ensure callers send a real JSON array (e.g. ["a", "b"], not "a") for array-typed parameters.
  3. Add template conditionals ({{if .param}}...{{end}}) or defaults so nil values never reach the helper.
  4. 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

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


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/4ce043a3835c1be3. Report an issue: GitHub.