googleapis/mcp-toolbox · error
expected item at index %d to be integer, got %T
Error message
expected item at index %d to be integer, got %T
What it means
ConvertAnySliceToTyped converts a []any into []int64 when itemType is "integer". Each element must be an `int` (Go native); if any element is not an int (e.g. float64 from JSON, or a string), the function aborts with this error naming the failing index.
Source
Thrown at internal/util/parameters/common.go:43
func ConvertAnySliceToTyped(s []any, itemType string) (any, error) {
var typedSlice any
switch itemType {
case "string":
tempSlice := make([]string, len(s))
for j, item := range s {
s, ok := item.(string)
if !ok {
return nil, fmt.Errorf("expected item at index %d to be string, got %T", j, item)
}
tempSlice[j] = s
}
typedSlice = tempSlice
case "integer":
tempSlice := make([]int64, len(s))
for j, item := range s {
i, ok := item.(int)
if !ok {
return nil, fmt.Errorf("expected item at index %d to be integer, got %T", j, item)
}
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)View on GitHub (pinned to 8cc6e09de2)
Solutions
- Ensure the input slice holds Go `int` values before calling, or pre-convert with a normalization loop
- If the source is JSON-decoded data, convert float64 elements (whole numbers) to int first
- Change the declared parameter type to 'float' if decimals are possible
- Have clients send unquoted integer literals in the tool call arguments
Example fix
// before
ConvertAnySliceToTyped([]any{float64(1), float64(2)}, "integer") // fails: float64 not int
// after
ConvertAnySliceToTyped([]any{1, 2}, "integer") Defensive patterns
Strategy: type-guard
Validate before calling
func allInts(v []any) bool {
for _, item := range v {
if _, ok := item.(int); !ok {
return false
}
}
return true
} Type guard
func isIntArray(v []any) bool {
for _, item := range v {
switch item.(type) {
case int, int64:
default:
return false
}
}
return true
} Try / catch
typed, err := ConvertAnySliceToTyped(s, "integer")
if err != nil {
return nil, fmt.Errorf("invalid integer array parameter: %w", err)
} Prevention
- Remember JSON decoding yields float64; convert to int before passing
- Normalize numeric strings ("5") to ints at the ingestion boundary
- Declare the schema element type as 'integer' so clients send real integers
When it happens
Trigger: Passing a slice containing float64, string, or bool values to ConvertAnySliceToTyped with itemType="integer", e.g. JSON-decoded arrays where numbers are float64, or clients sending quoted numbers ["1","2"].
Common situations: JSON unmarshalling makes all numbers float64, so integer array params fail; LLM sends "5" instead of 5; mixed-type arrays generated by an agent.
Related errors
- expected item at index %d to be string, got %T
- expected item at index %d to be float, got %T
- expected item at index %d to be boolean, 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/f1f9e8fd2f305a53.
Report an issue: GitHub.