{"record":{"id":"133c7f8039cce8c1","repo":"googleapis/mcp-toolbox","slug":"d-is-not-an-allowed-value","errorCode":null,"errorMessage":"%d is not an allowed value","messagePattern":"(.+?) is not an allowed value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/parameters/parameters.go","lineNumber":818,"sourceCode":"\tvar out int\n\tswitch newV := v.(type) {\n\tdefault:\n\t\treturn nil, &ParseTypeError{p.Name, p.Type, v}\n\tcase int:\n\t\tout = int(newV)\n\tcase int32:\n\t\tout = int(newV)\n\tcase int64:\n\t\tout = int(newV)\n\tcase json.Number:\n\t\tnewI, err := newV.Int64()\n\t\tif err != nil {\n\t\t\treturn nil, &ParseTypeError{p.Name, p.Type, v}\n\t\t}\n\t\tout = int(newI)\n\t}\n\tif !p.IsAllowedValues(out) {\n\t\treturn nil, fmt.Errorf(\"%d is not an allowed value\", out)\n\t}\n\tif p.IsExcludedValues(out) {\n\t\treturn nil, fmt.Errorf(\"%d is an excluded value\", out)\n\t}\n\tif p.MinValue != nil && out < *p.MinValue {\n\t\treturn nil, fmt.Errorf(\"%d is under the minimum value\", out)\n\t}\n\tif p.MaxValue != nil && out > *p.MaxValue {\n\t\treturn nil, fmt.Errorf(\"%d is above the maximum value\", out)\n\t}\n\treturn out, nil\n}\n\nfunc (p *IntParameter) GetAuthServices() []ParamAuthService {\n\treturn p.AuthServices\n}\n\nfunc (p *IntParameter) GetDefault() any {","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/parameters/parameters.go#L800-L836","documentation":"IntParameter.Parse rejects an integer because it is not present in the parameter's allowedValues list. The MCP Toolbox lets tool authors constrain numeric parameters to a fixed set; when an LLM or client supplies a value outside that set, parsing fails with this message. It is an expected validation rejection, not a bug in the library.","triggerScenarios":"Calling a tool (via MCP or the API) with an integer argument whose value is not listed in the IntParameter's allowedValues (configured with yaml 'allowedValues:' or WithIntAllowedValues). Example: allowedValues [1,2,3] but the request passes 7.","commonSituations":"LLMs hallucinating plausible-but-disallowed ids such as limit values, enum-like numeric codes, or page sizes; clients sending raw user input without pre-validation; tool configs tightened to a whitelist after clients were built against a looser schema.","solutions":["Read the tool's parameter manifest (GET /mcp or the tool schema) to see the exact allowedValues list and send one of those values","If the caller is an LLM, improve the parameter description to enumerate the valid values so the model picks within the set","If legitimate values are missing, add them to allowedValues in tools.yaml (or WithIntAllowedValues) and redeploy the toolbox","On the client side, validate the integer against the published manifest before invoking the tool"],"exampleFix":"// before\nparams := map[string]any{\"limit\": 500} // allowedValues are [10, 50, 100]\n// after\nparams := map[string]any{\"limit\": 100}","handlingStrategy":"validation","validationCode":"allowed := []int{10, 50, 100}\nfunc validateAllowedInt(v int, allowed []int) error {\n    for _, a := range allowed {\n        if v == a { return nil }\n    }\n    return fmt.Errorf(\"%d is not in allowedValues %v\", v, allowed)\n}","typeGuard":"func isAllowedInt(v int, allowed []int) bool {\n    for _, a := range allowed { if v == a { return true } }\n    return false\n}","tryCatchPattern":"out, err := tool.Parse(params)\nif err != nil {\n    var pte *ParseTypeError\n    if !errors.As(err, &pte) && strings.Contains(err.Error(), \"is not an allowed value\") {\n        // retry with a value from the manifest's allowedValues\n    }\n}","preventionTips":["Fetch the tool manifest and validate int params against allowedValues before invoking","Enumerate allowed values in the parameter description so LLMs choose correctly","Add config parsing tests covering allowedValues","Keep client-side whitelists in sync with tools.yaml changes"],"tags":["go","validation","parameters","integer"],"backgroundTag":"parameter-validation-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"}