github/github-mcp-server · error

parameter %s could not be coerced to []string, is %T

Error message

parameter %s could not be coerced to []string, is %T

What it means

Returned by OptionalStringArrayParam's default switch branch when the parameter is neither nil, []string, nor []any, i.e. the JSON value is a scalar or object where an array of strings is required. This is the top-level shape mismatch rather than an element-level one.

Source

Thrown at pkg/github/params.go:287

	}

	switch v := args[p].(type) {
	case nil:
		return []string{}, nil
	case []string:
		return v, nil
	case []any:
		strSlice := make([]string, len(v))
		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 {

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Wrap the value in a JSON array: ["bug"] even for a single item
  2. If you have a comma-separated string, split it client-side first and send the resulting array
  3. Align the tool's jsonschema type: array with items type string so clients generate the right shape

Example fix

// before
{"add_labels":"bug,priority"}
// after
{"add_labels":["bug","priority"]}
Defensive patterns

Strategy: validation

Validate before calling

func ensureStringSlice(args map[string]any, p string) error {
    switch args[p].(type) {
    case nil, []string, []any:
        return nil
    }
    return fmt.Errorf("%s must be a JSON array of strings", p)
}
// helper to fix single-string or joined inputs:
func toSlice(v any) []string {
    if s, ok := v.(string); ok {
        return strings.Split(s, ",")
    }
    return nil
}

Type guard

func isCoercibleToStringArray(v any) bool {
    switch v.(type) {
    case nil, []string, []any:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Passing a single string "bug" instead of ["bug"]; passing an integer or boolean; passing an object like {"0":"bug"}; clients that serialize arrays as comma-joined strings before sending.

Common situations: LLMs collapsing one-element arrays to scalars; users writing comma-separated strings like "bug,priority" expecting server-side splitting; schemas that declare type string where the handler requires array.

Related errors


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