googleapis/mcp-toolbox · error
failed to parse integer or float values in map: %s
Error message
failed to parse integer or float values in map: %s
What it means
For generic map parameters (no valueType declared), MapParameter.Parse runs util.ConvertNumbers to turn JSON numbers into int/float values. If any number in the map cannot be converted (e.g. out-of-range integer or a malformed numeric encoding), parsing fails with this message carrying the underlying conversion error.
Source
Thrown at internal/util/parameters/parameters.go:1346
}
// Parse validates and parses an incoming value for the map parameter.
func (p *MapParameter) Parse(v any) (any, error) {
m, ok := v.(map[string]any)
if !ok {
return nil, &ParseTypeError{p.Name, p.Type, v}
}
if !p.IsAllowedValues(m) {
return nil, fmt.Errorf("%s is not an allowed value", m)
}
if p.IsExcludedValues(m) {
return nil, fmt.Errorf("%s is an excluded value", m)
}
// for generic maps, convert json.Numbers to their corresponding types
if p.ValueType == "" {
convertedData, err := util.ConvertNumbers(m)
if err != nil {
return nil, fmt.Errorf("failed to parse integer or float values in map: %s", err)
}
convertedMap, ok := convertedData.(map[string]any)
if !ok {
return nil, fmt.Errorf("internal error: ConvertNumbers should return a map, but got type %T", convertedData)
}
return convertedMap, nil
}
// Otherwise, get a prototype and parse each value in the map.
prototype, err := getPrototypeParameter(p.ValueType)
if err != nil {
return nil, err
}
rtn := make(map[string]any, len(m))
for key, val := range m {
parsedVal, err := prototype.Parse(val)
if err != nil {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Check the wrapped inner error to find which value failed conversion.
- Send large numbers as strings if the tool treats them as identifiers.
- Declare an explicit valueType on the map parameter to change the conversion behavior, or fix the client-side number serialization.
Example fix
// before (number exceeds int64)
{"id": 99999999999999999999}
// after
{"id": "99999999999999999999"} Defensive patterns
Strategy: try-catch
Validate before calling
function safeNumbers(m) {
for (const [k, v] of Object.entries(m)) {
if (typeof v === 'number' && !Number.isSafeInteger(v) && Math.abs(v) > Number.MAX_SAFE_INTEGER) {
throw new Error(`value for '${k}' exceeds safe numeric range; send as string`);
}
}
}
safeNumbers(body.attrs); Type guard
function hasFiniteNumbers(m) {
return Object.values(m).every(v => typeof v !== 'number' || Number.isFinite(v));
} Try / catch
try {
await invokeTool('my_tool', body);
} catch (e) {
if (e.message.includes('failed to parse integer or float values in map')) {
console.error('Fix numeric values in map payload (range/format):', e.message);
} else throw e;
} Prevention
- Send very large numbers as strings when they are identifiers.
- Use standard JSON encoders client-side.
- Declare explicit valueType for maps with heavy numeric content and test payload edge cases.
When it happens
Trigger: Sending a map with no declared valueType where a value is a JSON number that ConvertNumbers cannot handle — e.g. an integer exceeding int64 range, or an unexpected numeric literal in the decoded payload.
Common situations: Clients sending huge IDs as numbers instead of strings; floating point values with extreme exponents; a backend/client JSON encoder producing non-standard numeric formats.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- %t is an excluded value
- unable to parse element #%d: %w
- Invalid JSON format for ${paramName}. Expected an array. ${e
- Input for ${paramName} must be a JSON array (e.g., ["a", "b"
- /api native endpoints are disabled by default. Please use th
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/a02e399b1735c855.
Report an issue: GitHub.