{"record":{"id":"0db05f551aab5e7c","repo":"googleapis/mcp-toolbox","slug":"unable-to-parse-element-d-w","errorCode":null,"errorMessage":"unable to parse element #%d: %w","messagePattern":"unable to parse element #(.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/parameters.go","lineNumber":1166,"sourceCode":"\treturn false\n}\n\nfunc (p *ArrayParameter) Parse(v any) (any, error) {\n\tarrVal, ok := v.([]any)\n\tif !ok {\n\t\treturn nil, &ParseTypeError{p.Name, p.Type, v}\n\t}\n\tif !p.IsAllowedValues(arrVal) {\n\t\treturn nil, fmt.Errorf(\"%s is not an allowed value\", arrVal)\n\t}\n\tif p.IsExcludedValues(arrVal) {\n\t\treturn nil, fmt.Errorf(\"%s is an excluded value\", arrVal)\n\t}\n\trtn := make([]any, 0, len(arrVal))\n\tfor idx, val := range arrVal {\n\t\tval, err := p.Items.Parse(val)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to parse element #%d: %w\", idx, err)\n\t\t}\n\t\trtn = append(rtn, val)\n\t}\n\treturn rtn, nil\n}\n\nfunc (p *ArrayParameter) GetAuthServices() []ParamAuthService {\n\treturn p.AuthServices\n}\n\nfunc (p *ArrayParameter) GetDefault() any {\n\tif p.Default == nil {\n\t\treturn nil\n\t}\n\treturn *p.Default\n}\n\nfunc (p *ArrayParameter) GetItems() Parameter {","sourceCodeStart":1148,"sourceCodeEnd":1184,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/parameters.go#L1148-L1184","documentation":"After validating the array itself, ArrayParameter.Parse calls Items.Parse on each element. If any element fails its own parse/validation (wrong type, not allowed, excluded, nested map failure, etc.), the error is wrapped as 'unable to parse element #%d' with the zero-based index.","triggerScenarios":"Sending an array where at least one element does not satisfy the items schema — e.g. array of integers with one string element, or array items having their own allowedValues that an element violates.","commonSituations":"Mixed-type arrays from dynamic client code; strings like '1' instead of integers 1; nested arrays whose inner element fails validation.","solutions":["Look at the element index in the wrapped message and check the inner error for the root cause.","Ensure every element matches the declared items type (string/integer/boolean/float/array/map).","Pre-validate the payload client-side against the tool's parameter manifest before invoking."],"exampleFix":"// before\n{\"ids\": [1, 2, \"three\"]}  // items type: integer\n// after\n{\"ids\": [1, 2, 3]}","handlingStrategy":"type-guard","validationCode":"const itemsType = 'integer';\nbody.ids.forEach((el, i) => {\n  if (typeof el !== 'number') throw new Error(`element #${i} is not an integer`);\n});","typeGuard":"function isArrayOf(v, pred) { return Array.isArray(v) && v.every(pred); }\n// usage: isArrayOf(body.ids, n => Number.isInteger(n))","tryCatchPattern":"try {\n  await invokeTool('my_tool', body);\n} catch (e) {\n  if (/unable to parse element #(\\d+)/.test(e.message)) {\n    const idx = e.message.match(/#(\\d+)/)[1];\n    console.error(`Fix array element at index ${idx}: ${e.message}`);\n  } else throw e;\n}","preventionTips":["Validate arrays element-by-element against the items type before sending.","Avoid mixed-type arrays from dynamic user input.","Wrap tool invocations and surface the element index in client errors."],"tags":["parameter-validation","array","type-error","mcp-toolbox"],"backgroundTag":"parameter-type-mismatch","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"}