googleapis/mcp-toolbox · error

only one of 'collection' or 'collectionAllowedValues' can be

Error message

only one of 'collection' or 'collectionAllowedValues' can be set, not both

What it means

mongodbcommon.ValidateCollectionConfig enforces that a MongoDB tool picks its target collection in exactly one way: either a fixed `collection` in the tool config, or a runtime `collection` parameter constrained by `collectionAllowedValues` — never both. Setting both is ambiguous, so initialization fails with this error.

Source

Thrown at internal/tools/mongodb/mongodbcommon/util.go:31

// limitations under the License.

// Package mongodbcommon holds helpers shared across the MongoDB tools.
package mongodbcommon

import (
	"fmt"

	"github.com/googleapis/mcp-toolbox/internal/util"
	"github.com/googleapis/mcp-toolbox/internal/util/parameters"
)

// CollectionKey is the runtime parameter name used to pick a collection.
const CollectionKey string = "collection"

// ValidateCollectionConfig rejects setting collection and collectionAllowedValues together.
func ValidateCollectionConfig(collection string, allowedValues []string) error {
	if collection != "" && len(allowedValues) > 0 {
		return fmt.Errorf("only one of 'collection' or 'collectionAllowedValues' can be set, not both")
	}
	return nil
}

// WithRuntimeCollectionParam adds a required collection parameter when none is set in config.
func WithRuntimeCollectionParam(collection string, allowedValues []string, params parameters.Parameters) parameters.Parameters {
	if collection != "" {
		return params
	}
	opts := []parameters.StringParameterOption{parameters.WithStringRequired(true)}
	if len(allowedValues) > 0 {
		allowed := make([]any, len(allowedValues))
		for i, v := range allowedValues {
			allowed[i] = v
		}
		opts = append(opts, parameters.WithStringAllowedValues(allowed))
	}
	collectionParam := parameters.NewStringParameter(CollectionKey, "The name of the collection to operate on.", opts...)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Remove `collectionAllowedValues` if you want a fixed `collection` in config
  2. Remove the `collection` field and keep `collectionAllowedValues` if the collection should be chosen at runtime
  3. Keep only one of the two keys in the tool's YAML block

Example fix

// before
my-tool:
  kind: mongodb-aggregate
  source: my-mongo
  collection: orders
  collectionAllowedValues: [orders, customers]
// after
my-tool:
  kind: mongodb-aggregate
  source: my-mongo
  collection: orders
Defensive patterns

Strategy: validation

Validate before calling

cfg, _ := yaml.Marshal(toolCfg)
var t struct {
    Collection              string   `yaml:"collection"`
    CollectionAllowedValues []string `yaml:"collectionAllowedValues"`
}
yaml.Unmarshal(cfg, &t)
if t.Collection != "" && len(t.CollectionAllowedValues) > 0 {
    return errors.New("set only one of collection or collectionAllowedValues")
}

Prevention

When it happens

Trigger: Declaring a MongoDB tool config (e.g. mongodb-aggregate, mongodb-delete-many) where `collection` is non-empty AND `collectionAllowedValues` has at least one entry; ValidateCollectionConfig is called from Initialize and from parameter-processing anonymous functions.

Common situations: Migrating from a fixed-collection tool to a runtime-collection tool but forgetting to remove the old `collection` field; copy-pasting a template that includes both keys; merging two tool definitions.

Related errors


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