{"record":{"id":"0486429aa6a90961","repo":"googleapis/mcp-toolbox","slug":"limit-must-be-a-positive-number-but-got-d","errorCode":null,"errorMessage":"limit must be a positive number, but got %d","messagePattern":"limit must be a positive number, but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/mongodb/mongodbfind/mongodbfind.go","lineNumber":96,"sourceCode":"\nfunc (cfg Config) Initialize(context.Context) (tools.Tool, error) {\n\tif cfg.Description == \"\" {\n\t\treturn nil, fmt.Errorf(\"description is required for tool %q\", cfg.Name)\n\t}\n\n\tallParameters := slices.Concat(cfg.FilterParams, cfg.ProjectParams, cfg.SortParams)\n\n\tif err := mongodbcommon.ValidateCollectionConfig(cfg.Collection, cfg.CollectionAllowedValues); err != nil {\n\t\treturn nil, err\n\t}\n\tallParameters = mongodbcommon.WithRuntimeCollectionParam(cfg.Collection, cfg.CollectionAllowedValues, allParameters)\n\n\tif err := parameters.CheckDuplicateParameters(allParameters); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif cfg.Limit <= 0 {\n\t\treturn nil, fmt.Errorf(\"limit must be a positive number, but got %d\", cfg.Limit)\n\t}\n\n\tparamManifest := allParameters.Manifest()\n\tif paramManifest == nil {\n\t\tparamManifest = make([]parameters.ParameterManifest, 0)\n\t}\n\n\treturn Tool{\n\t\tBaseTool: tools.NewBaseTool(\n\t\t\tcfg,\n\t\t\ttools.GetAnnotationsOrDefault(cfg.Annotations, tools.NewReadOnlyAnnotations),\n\t\t\ttools.Manifest{Description: cfg.Description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},\n\t\t\tallParameters,\n\t\t),\n\t}, nil\n}\n\n// validate interface","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/mongodb/mongodbfind/mongodbfind.go#L78-L114","documentation":"The mongodb-find tool's Initialize validates that cfg.Limit is strictly positive, since MongoDB's find options require a positive limit and a zero/negative value is meaningless. A non-positive limit aborts tool initialization.","triggerScenarios":"Configuring a mongodb-find tool with limit: 0, a negative number, or omitting it in a way that leaves the field at 0 (or below) before Initialize runs.","commonSituations":"Setting limit to 0 believing it means 'unlimited'; copying configs where limit was left blank; computing limit from an env var or expression that evaluates to <= 0; integer type mismatch losing the value.","solutions":["Set limit to a positive integer in the tool config (e.g. limit: 10).","If unlimited results are desired, remove the limit field if supported, or use a large positive value.","Validate any dynamic limit value before placing it in the config."],"exampleFix":"# before\n  find-users:\n    kind: mongodb-find\n    source: my-mongo\n    limit: 0\n# after\n  find-users:\n    kind: mongodb-find\n    source: my-mongo\n    limit: 50","handlingStrategy":"validation","validationCode":"if cfg.Limit <= 0 {\n    return errors.New(\"mongodb-find limit must be > 0\")\n}","typeGuard":"func hasValidLimit(c mongodbfind.Config) bool { return c.Limit > 0 }","tryCatchPattern":"tool, err := cfg.Initialize(context.Background())\nif err != nil && strings.Contains(err.Error(), \"limit must be a positive number\") {\n    cfg.Limit = 10 // safe default\n    tool, err = cfg.Initialize(context.Background())\n}","preventionTips":["Remember limit is a cap, not an 'unlimited' flag — use a positive value.","When sourcing limit from env/flags, validate > 0 before building the config.","Document sensible default limits in your tool templates."],"tags":["go","mongodb","config-validation","parameter-validation"],"backgroundTag":"invalid-argument-value","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"}