{"record":{"id":"a02e399b1735c855","repo":"googleapis/mcp-toolbox","slug":"failed-to-parse-integer-or-float-values-in-map-s","errorCode":null,"errorMessage":"failed to parse integer or float values in map: %s","messagePattern":"failed to parse integer or float values in map: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/parameters.go","lineNumber":1346,"sourceCode":"}\n\n// Parse validates and parses an incoming value for the map parameter.\nfunc (p *MapParameter) Parse(v any) (any, error) {\n\tm, ok := v.(map[string]any)\n\tif !ok {\n\t\treturn nil, &ParseTypeError{p.Name, p.Type, v}\n\t}\n\tif !p.IsAllowedValues(m) {\n\t\treturn nil, fmt.Errorf(\"%s is not an allowed value\", m)\n\t}\n\tif p.IsExcludedValues(m) {\n\t\treturn nil, fmt.Errorf(\"%s is an excluded value\", m)\n\t}\n\t// for generic maps, convert json.Numbers to their corresponding types\n\tif p.ValueType == \"\" {\n\t\tconvertedData, err := util.ConvertNumbers(m)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse integer or float values in map: %s\", err)\n\t\t}\n\t\tconvertedMap, ok := convertedData.(map[string]any)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"internal error: ConvertNumbers should return a map, but got type %T\", convertedData)\n\t\t}\n\t\treturn convertedMap, nil\n\t}\n\n\t// Otherwise, get a prototype and parse each value in the map.\n\tprototype, err := getPrototypeParameter(p.ValueType)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\trtn := make(map[string]any, len(m))\n\tfor key, val := range m {\n\t\tparsedVal, err := prototype.Parse(val)\n\t\tif err != nil {","sourceCodeStart":1328,"sourceCodeEnd":1364,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/parameters.go#L1328-L1364","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (number exceeds int64)\n{\"id\": 99999999999999999999}\n// after\n{\"id\": \"99999999999999999999\"}","handlingStrategy":"try-catch","validationCode":"function safeNumbers(m) {\n  for (const [k, v] of Object.entries(m)) {\n    if (typeof v === 'number' && !Number.isSafeInteger(v) && Math.abs(v) > Number.MAX_SAFE_INTEGER) {\n      throw new Error(`value for '${k}' exceeds safe numeric range; send as string`);\n    }\n  }\n}\nsafeNumbers(body.attrs);","typeGuard":"function hasFiniteNumbers(m) {\n  return Object.values(m).every(v => typeof v !== 'number' || Number.isFinite(v));\n}","tryCatchPattern":"try {\n  await invokeTool('my_tool', body);\n} catch (e) {\n  if (e.message.includes('failed to parse integer or float values in map')) {\n    console.error('Fix numeric values in map payload (range/format):', e.message);\n  } else throw e;\n}","preventionTips":["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."],"tags":["parameter-validation","map","json-number","mcp-toolbox"],"backgroundTag":"json-number-conversion-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}