googleapis/mcp-toolbox · error
limit must be a positive number, but got %d
Error message
limit must be a positive number, but got %d
What it means
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.
Source
Thrown at internal/tools/mongodb/mongodbfind/mongodbfind.go:96
func (cfg Config) Initialize(context.Context) (tools.Tool, error) {
if cfg.Description == "" {
return nil, fmt.Errorf("description is required for tool %q", cfg.Name)
}
allParameters := slices.Concat(cfg.FilterParams, cfg.ProjectParams, cfg.SortParams)
if err := mongodbcommon.ValidateCollectionConfig(cfg.Collection, cfg.CollectionAllowedValues); err != nil {
return nil, err
}
allParameters = mongodbcommon.WithRuntimeCollectionParam(cfg.Collection, cfg.CollectionAllowedValues, allParameters)
if err := parameters.CheckDuplicateParameters(allParameters); err != nil {
return nil, err
}
if cfg.Limit <= 0 {
return nil, fmt.Errorf("limit must be a positive number, but got %d", cfg.Limit)
}
paramManifest := allParameters.Manifest()
if paramManifest == nil {
paramManifest = make([]parameters.ParameterManifest, 0)
}
return Tool{
BaseTool: tools.NewBaseTool(
cfg,
tools.GetAnnotationsOrDefault(cfg.Annotations, tools.NewReadOnlyAnnotations),
tools.Manifest{Description: cfg.Description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
allParameters,
),
}, nil
}
// validate interfaceView on GitHub (pinned to 8cc6e09de2)
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.
Example fix
# before
find-users:
kind: mongodb-find
source: my-mongo
limit: 0
# after
find-users:
kind: mongodb-find
source: my-mongo
limit: 50 Defensive patterns
Strategy: validation
Validate before calling
if cfg.Limit <= 0 {
return errors.New("mongodb-find limit must be > 0")
} Type guard
func hasValidLimit(c mongodbfind.Config) bool { return c.Limit > 0 } Try / catch
tool, err := cfg.Initialize(context.Background())
if err != nil && strings.Contains(err.Error(), "limit must be a positive number") {
cfg.Limit = 10 // safe default
tool, err = cfg.Initialize(context.Background())
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- description is required for tool %q
- only one of 'collection' or 'collectionAllowedValues' can be
- description is required for tool %q
- description is required for tool %q
- description is required for tool %q
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/0486429aa6a90961.
Report an issue: GitHub.