googleapis/mcp-toolbox · error

error populating project payload: %s

Error message

error populating project payload: %s

What it means

During find-option construction, the tool renders the project payload template against the resolved parameters via parameters.PopulateTemplateWithJSON. If template rendering fails (malformed template syntax, missing parameters, invalid JSON payload), the error is wrapped as 'error populating project payload'. It indicates the projection template could not be produced from the supplied parameter values.

Source

Thrown at internal/tools/mongodb/mongodbfind/mongodbfind.go:156

	logger, err := util.LoggerFromContext(ctx)
	if err != nil {
		return nil, err
	}

	opts := options.Find()

	sort := bson.M{}
	for _, p := range sortParameters {
		sort[p.GetName()] = paramsMap[p.GetName()]
	}
	opts = opts.SetSort(sort)

	if len(projectPayload) > 0 {

		result, err := parameters.PopulateTemplateWithJSON("MongoDBFindProjectString", projectPayload, paramsMap)

		if err != nil {
			return nil, fmt.Errorf("error populating project payload: %s", err)
		}

		var projection any
		err = bson.UnmarshalExtJSON([]byte(result), false, &projection)
		if err != nil {
			return nil, fmt.Errorf("error unmarshalling projection: %s", err)
		}

		opts = opts.SetProjection(projection)
		logger.DebugContext(ctx, fmt.Sprintf("Projection is set to %v", projection))
	}

	if limit > 0 {
		opts = opts.SetLimit(limit)
		logger.DebugContext(ctx, fmt.Sprintf("Limit is being set to %d", limit))
	}
	return opts, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Fix the project payload JSON/template syntax in the tool config.
  2. Ensure every placeholder in the project payload matches a declared parameter.
  3. Check the parameters sent by the client include all values the projection template needs.

Example fix

// before
project: '{ "name": {{.params.name}} }'   // malformed template
// after
project: '{ "name": 1, "email": 1 }'
Defensive patterns

Strategy: validation

Validate before calling

// Go: verify every placeholder in the project payload has a matching param
for _, name := range extractPlaceholders(projectPayload) {
    if _, ok := paramsMap[name]; !ok {
        return fmt.Errorf("missing param %q for project payload", name)
    }
}

Try / catch

opts, err := getOptions(ctx, sortParams, projectPayload, limit, paramsMap)
if err != nil && strings.Contains(err.Error(), "error populating project payload") {
    // fall back: drop projection and query without it
    opts, err = getOptions(ctx, sortParams, "", limit, paramsMap)
}

Prevention

When it happens

Trigger: Invoke() on a mongodb-find tool whose projectPayload contains template placeholders not present in paramsMap, or whose project payload is not valid JSON/template syntax.

Common situations: Referencing a parameter name in the project payload that isn't declared in the tool's parameters; JSON typos in the project string; auth参数-backed params absent at invocation time; clients sending incomplete parameter sets.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/79f1c8e1e594692a. Report an issue: GitHub.