googleapis/mcp-toolbox · error

failed to marshal generation options map: %w

Error message

failed to marshal generation options map: %w

What it means

After successfully parsing YAML into map[string]any, UnmarshalYAML re-serializes the map to JSON via json.Marshal so protojson can consume it. This error fires if the map contains values that encoding/json cannot serialize. It is rare in practice because YAML-parsed values are almost always JSON-compatible.

Source

Thrown at internal/tools/cloudgda/cloudgda.go:102

	if err := protojson.Unmarshal(jsonBytes, q.QueryDataContext); err != nil {
		return fmt.Errorf("failed to unmarshal context to proto: %w", err)
	}
	return nil
}

// GenerationOptions wraps geminidataanalyticspb.GenerationOptions to support YAML decoding via protojson.
type GenerationOptions struct {
	*geminidataanalyticspb.GenerationOptions
}

func (g *GenerationOptions) UnmarshalYAML(b []byte) error {
	var raw map[string]any
	if err := yaml.Unmarshal(b, &raw); err != nil {
		return fmt.Errorf("failed to unmarshal generation options from yaml: %w", err)
	}
	jsonBytes, err := json.Marshal(raw)
	if err != nil {
		return fmt.Errorf("failed to marshal generation options map: %w", err)
	}
	g.GenerationOptions = &geminidataanalyticspb.GenerationOptions{}
	if err := protojson.Unmarshal(jsonBytes, g.GenerationOptions); err != nil {
		return fmt.Errorf("failed to unmarshal generation options to proto: %w", err)
	}
	return nil
}

type Config struct {
	tools.ConfigBase  `yaml:",inline"`
	Type              string                 `yaml:"type" validate:"required"`
	Source            string                 `yaml:"source" validate:"required"`
	Location          string                 `yaml:"location" validate:"required"`
	Context           *QueryDataContext      `yaml:"context" validate:"required"`
	GenerationOptions *GenerationOptions     `yaml:"generationOptions,omitempty"`
	Annotations       *tools.ToolAnnotations `yaml:"annotations,omitempty"`
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check numeric literals in generationOptions for out-of-range values and quote or reduce them
  2. Ensure the generationOptions block contains only plain JSON-compatible types (maps, lists, strings, numbers, bools)
  3. Simplify the block and re-add fields until the offending value is isolated
  4. File an issue with the exact YAML snippet if a valid value still fails

Example fix

// before
generationOptions:
  hugeNumber: 1e400
// after
generationOptions:
  hugeNumber: "1e400"
Defensive patterns

Strategy: validation

Validate before calling

import ("encoding/json"; "gopkg.in/yaml.v3")
func validJSONRoundTrip(b []byte) error {
	var m map[string]any
	if err := yaml.Unmarshal(b, &m); err != nil { return err }
	_, err := json.Marshal(m)
	return err
}

Prevention

When it happens

Trigger: A generationOptions YAML value that decodes into a Go type json.Marshal cannot handle, e.g. very large numbers beyond float64 range, or a custom scalar decode producing an unsupported type.

Common situations: Extremely large integer literals (e.g. 1e309 / huge uint64) in the YAML block; exotic YAML tags or timestamps injected via custom decode hooks.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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