googleapis/mcp-toolbox · error
failed to unmarshal generation options to proto: %w
Error message
failed to unmarshal generation options to proto: %w
What it means
The JSON bytes produced from the YAML map are unmarshaled into the protobuf message geminidataanalyticspb.GenerationOptions using protojson. This error fires when keys or value shapes do not match the proto schema (protojson validates field names and types strictly, unlike plain JSON decoding).
Source
Thrown at internal/tools/cloudgda/cloudgda.go:106
}
// 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"`
}
// validate interface
var _ tools.ToolConfig = Config{}
func (cfg Config) ToolConfigType() string {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Check each key in generationOptions against the GenerationOptions proto message in google.golang.org/api/geminidataanalytics/v1alpha (or matching version) and fix names/types
- Use exact proto field names (the JSON names, typically lowerCamelCase) for all keys
- Remove unknown keys; protojson with default options rejects them
- Pin a matching google-api-go-client version so the proto schema matches your intended fields
Example fix
// before (unknown field 'queryMod', wrong enum type) generationOptions: queryMod: "AUTO" // after generationOptions: queryMode: AUTO
Defensive patterns
Strategy: validation
Validate before calling
import ("encoding/json"; "google.golang.org/protobuf/encoding/protojson")
func validProtoShape(b []byte, msg proto.Message) error {
var m map[string]any
if err := yaml.Unmarshal(b, &m); err != nil { return err }
jb, _ := json.Marshal(m)
return protojson.Unmarshal(jb, msg)
} Prevention
- Cross-check every generationOptions key against the GenerationOptions proto definition
- Use exact proto JSON field names (lowerCamelCase)
- Pin the google-api-go-client version matching your field names
When it happens
Trigger: Using unknown field names in generationOptions (protojson rejects unknown fields by default), wrong value types for known fields (e.g. a string where an enum name or bool is expected), or mapping under a field that is not a message.
Common situations: Typos in proto field names (e.g. queryMod instead of queryMode); using camelCase vs snake_case inconsistently; copying options from a different API version whose schema changed; nesting a map where proto expects a scalar.
Related errors
- failed to unmarshal generation options from yaml: %w
- failed to marshal generation options map: %w
- doc %d: unexpected non-string key in input: %v
- doc %d: invalid config format at key %q: %w
- doc %d: invalid config format at key %q: expected nested for
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/40050c20efa2198a.
Report an issue: GitHub.