github/github-mcp-server · error

failed to convert element %d (%s) to int64: %w

Error message

failed to convert element %d (%s) to int64: %w

What it means

Returned by convertStringSliceToBigIntSlice when one element of an already-[]string array fails convertStringToBigInt (strconv.ParseInt base 10, 64-bit). The message includes the failing index and original string so the offending element is identifiable, and the wrapped ParseInt error distinguishes syntax from range failures.

Source

Thrown at pkg/github/params.go:296

		for i, v := range v {
			s, ok := v.(string)
			if !ok {
				return []string{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v)
			}
			strSlice[i] = s
		}
		return strSlice, nil
	default:
		return []string{}, fmt.Errorf("parameter %s could not be coerced to []string, is %T", p, args[p])
	}
}

func convertStringSliceToBigIntSlice(s []string) ([]int64, error) {
	int64Slice := make([]int64, len(s))
	for i, str := range s {
		val, err := convertStringToBigInt(str, 0)
		if err != nil {
			return nil, fmt.Errorf("failed to convert element %d (%s) to int64: %w", i, str, err)
		}
		int64Slice[i] = val
	}
	return int64Slice, nil
}

func convertStringToBigInt(s string, def int64) (int64, error) {
	v, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		return def, fmt.Errorf("failed to convert string %s to int64: %w", s, err)
	}
	return v, nil
}

// OptionalBigIntArrayParam is a helper function that can be used to fetch a requested parameter from the request.
// It does the following checks:
// 1. Checks if the parameter is present in the request, if not, it returns an empty slice
// 2. If it is present, iterates the elements, checks each is a string, and converts them to int64 values

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Pass IDs as plain base-10 digit strings without separators, signs, spaces, or exponent notation
  2. Sanitize externally sourced strings (trim, strip commas) before building the array
  3. For out-of-range values, verify the source actually returned an int64-sized ID — if not, the wrong field is being collected

Example fix

// before
{"repository_ids":["123", "1,402", ""]}
// after
{"repository_ids":["123","1402"]}
Defensive patterns

Strategy: validation

Validate before calling

func validateIDStrings(ids []string) error {
    for i, s := range ids {
        if _, err := strconv.ParseInt(s, 10, 64); err != nil {
            return fmt.Errorf("element %d (%q) is not a valid int64: %w", i, s, err)
        }
    }
    return nil
}

Type guard

func allElementsInt64(s []string) bool {
    for _, v := range s {
        if _, err := strconv.ParseInt(v, 10, 64); err != nil {
            return false
        }
    }
    return true
}

Try / catch

ids, err := github.OptionalStringArrayParam(args, "repository_ids")
if err != nil {
    return err
}
if err := validateIDStrings(ids); err != nil {
    // drop or repair bad elements before converting downstream
    return err
}

Prevention

When it happens

Trigger: An element like "12.5", "1e5", " 42", "", "0x1F", or a value beyond int64 range; an empty-string element in an otherwise numeric list; elements with thousands separators such as "1,000,000".

Common situations: Forwarding display-formatted or localized numbers (IDs with commas) into ID-array parameters like repository_ids or issue IDs; LLM-generated lists mixing label names with numeric IDs in one array; copy/paste introducing invisible whitespace.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/15361389c2f956c2. Report an issue: GitHub.