{"record":{"id":"46aeaa370325d4e8","repo":"github/github-mcp-server","slug":"non-finite-numeric-value","errorCode":null,"errorMessage":"non-finite numeric value","messagePattern":"non-finite numeric value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/github/params.go","lineNumber":81,"sourceCode":"// toInt converts a value to int, handling both float64 and string representations.\n// Some MCP clients send numeric values as strings. It rejects NaN, ±Inf,\n// fractional values, and values outside the int range.\nfunc toInt(val any) (int, error) {\n\tvar f float64\n\tswitch v := val.(type) {\n\tcase float64:\n\t\tf = v\n\tcase string:\n\t\tvar err error\n\t\tf, err = strconv.ParseFloat(v, 64)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"invalid numeric value: %s\", v)\n\t\t}\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"expected number, got %T\", val)\n\t}\n\tif math.IsNaN(f) || math.IsInf(f, 0) {\n\t\treturn 0, fmt.Errorf(\"non-finite numeric value\")\n\t}\n\tif f != math.Trunc(f) {\n\t\treturn 0, fmt.Errorf(\"non-integer numeric value: %v\", f)\n\t}\n\tif f > math.MaxInt || f < math.MinInt {\n\t\treturn 0, fmt.Errorf(\"numeric value out of int range: %v\", f)\n\t}\n\treturn int(f), nil\n}\n\n// toInt64 converts a value to int64, handling both float64 and string representations.\n// Some MCP clients send numeric values as strings. It rejects NaN, ±Inf,\n// fractional values, and values that lose precision in the float64→int64 conversion.\nfunc toInt64(val any) (int64, error) {\n\tvar f float64\n\tswitch v := val.(type) {\n\tcase float64:\n\t\tf = v","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/params.go#L63-L99","documentation":"Thrown by toInt in pkg/github/params.go when the parsed numeric value is NaN or ±Inf. Standard JSON cannot carry these values, so in practice they arrive as strings that Go's ParseFloat happily accepts (\"NaN\", \"Inf\", \"+Inf\", \"-Infinity\") and are then rejected as non-finite before integer conversion.","triggerScenarios":"page: \"NaN\" or per_page: \"Infinity\" sent to an int parameter; client code stringifying a computed Infinity/NaN (e.g. division by zero formatted to string) into the arguments.","commonSituations":"Downstream calculations (percentages, counts) that yield NaN/Infinity being forwarded without checks; copy-paste of literal debug values; clients mapping JavaScript's Infinity to the string \"Infinity\".","solutions":["Fix the upstream computation so it never produces NaN/Infinity (guard divide-by-zero, check Number.isFinite before sending).","Send a concrete integer value for the parameter.","Validate arguments client-side with Number.isFinite when the value originates from math."],"exampleFix":"// before\nconst page = String(total / perPage); // \"Infinity\" or \"NaN\"\narguments = { owner, repo, page };\n// after\nconst page = Number.isFinite(total / perPage) ? total / perPage : 1;\narguments = { owner, repo, page };","handlingStrategy":"validation","validationCode":"function finiteNumber(v, fallback) {\n  return typeof v === \"number\" && Number.isFinite(v) ? v : fallback;\n}\n// when building arguments from computed values:\nargs.page = finiteNumber(computedPage, 1);","typeGuard":"function isFiniteNumberLike(v: unknown): v is number {\n  return typeof v === \"number\" && Number.isFinite(v);\n}","tryCatchPattern":"On 'non-finite numeric value', trace which computed argument produced NaN/Infinity, fix the computation (usually a divide-by-zero or missing total), then retry.","preventionTips":["Guard every division used for pagination/count math with a zero check.","Never stringify NaN/Infinity into payloads; fail loudly client-side instead.","Treat non-finite intermediates as data bugs, not server defaults."],"tags":["validation","numeric","non-finite","argument-parsing","mcp-tool"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}