googleapis/mcp-toolbox · error
expected item at index %d to be boolean, got %T
Error message
expected item at index %d to be boolean, got %T
What it means
ConvertAnySliceToTyped converts a []any into []bool when itemType is "boolean". Each element must be exactly a Go `bool`; anything else (strings "true"/"false", numbers) triggers this error at the failing index.
Source
Thrown at internal/util/parameters/common.go:63
tempSlice[j] = int64(i)
}
typedSlice = tempSlice
case "float":
tempSlice := make([]float64, len(s))
for j, item := range s {
f, ok := item.(float64)
if !ok {
return nil, fmt.Errorf("expected item at index %d to be float, got %T", j, item)
}
tempSlice[j] = f
}
typedSlice = tempSlice
case "boolean":
tempSlice := make([]bool, len(s))
for j, item := range s {
b, ok := item.(bool)
if !ok {
return nil, fmt.Errorf("expected item at index %d to be boolean, got %T", j, item)
}
tempSlice[j] = b
}
typedSlice = tempSlice
}
return typedSlice, nil
}
// convertParamToJSON is a Go template helper function to convert a parameter to JSON formatted string.
func convertParamToJSON(param any) (string, error) {
jsonData, err := json.Marshal(param)
if err != nil {
return "", fmt.Errorf("failed to marshal param to JSON: %w", err)
}
return string(jsonData), nil
}
// PopulateTemplateWithJSON populate a Go template with a custom `json` array formatterView on GitHub (pinned to 8cc6e09de2)
Solutions
- Have callers send native JSON booleans (true/false), not strings
- Pre-normalize string flags to bool (parse "true"/"1" etc.) before calling
- If string flags are unavoidable, use itemType="string" and convert downstream
- Check the tool manifest schema to confirm the array element type is boolean
Example fix
// before
ConvertAnySliceToTyped([]any{"true"}, "boolean") // fails
// after
ConvertAnySliceToTyped([]any{true}, "boolean") Defensive patterns
Strategy: type-guard
Validate before calling
func allBools(v []any) bool {
for _, item := range v {
if _, ok := item.(bool); !ok {
return false
}
}
return true
} Type guard
func isBoolArray(v []any) bool {
for _, item := range v {
if _, ok := item.(bool); !ok {
return false
}
}
return true
} Try / catch
typed, err := ConvertAnySliceToTyped(s, "boolean")
if err != nil {
return nil, fmt.Errorf("invalid boolean array parameter: %w", err)
} Prevention
- Send native JSON booleans, not "true"/"1" strings
- Parse string flags with strconv.ParseBool at the boundary if strings are unavoidable
- Validate against the manifest schema before invoking
When it happens
Trigger: Passing []any{"true"} or []any{1} with itemType="boolean" — commonly from clients serializing booleans as strings or from agent-generated arguments.
Common situations: Form/query string inputs where booleans arrive as strings; YAML configs with unquoted yes/no; LLM emitting "true" instead of true.
Related errors
- expected item at index %d to be string, got %T
- expected item at index %d to be integer, got %T
- expected item at index %d to be float, got %T
- unable to bind: %w
- 'model' must be a string, got %T
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/c5af3c76782cd70b.
Report an issue: GitHub.