googleapis/mcp-toolbox · error
failed to unmarshal context from yaml: %w
Error message
failed to unmarshal context from yaml: %w
What it means
QueryDataContext.UnmarshalYAML first parses the YAML bytes into a generic map before converting to the proto message. If the YAML itself is malformed (bad indentation, tabs, invalid syntax), the yaml.Unmarshal step fails and this wrapped error is returned. It means the `context` block in a cloud-gda tool config could not even be parsed as YAML.
Source
Thrown at internal/tools/cloudgda/cloudgda.go:77
}
return actual, nil
}
type compatibleSource interface {
GetProjectID() string
UseClientAuthorization() bool
RunQuery(context.Context, string, *geminidataanalyticspb.QueryDataRequest) (*geminidataanalyticspb.QueryDataResponse, error)
}
// QueryDataContext wraps geminidataanalyticspb.QueryDataContext to support YAML decoding via protojson.
type QueryDataContext struct {
*geminidataanalyticspb.QueryDataContext
}
func (q *QueryDataContext) UnmarshalYAML(b []byte) error {
var raw map[string]any
if err := yaml.Unmarshal(b, &raw); err != nil {
return fmt.Errorf("failed to unmarshal context from yaml: %w", err)
}
jsonBytes, err := json.Marshal(raw)
if err != nil {
return fmt.Errorf("failed to marshal context map: %w", err)
}
q.QueryDataContext = &geminidataanalyticspb.QueryDataContext{}
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 {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Validate the YAML snippet with a linter (yamllint or an editor) and fix the syntax error named in the wrapped message.
- Replace tab characters with spaces in the context block.
- Quote strings containing special characters (:, #, {, }) properly.
- Compare against a working cloud-gda example config in docs/en.
Example fix
// before (invalid)
context:
tableReferences:
- tableName: orders
// after
context:
tableReferences:
- tableName: orders Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate the context YAML before loading the config
import "gopkg.in/yaml.v3"
func validateContextYAML(s string) error {
var m map[string]any
if err := yaml.Unmarshal([]byte(s), &m); err != nil {
return fmt.Errorf("invalid context YAML: %w", err)
}
return nil
} Try / catch
var qd QueryDataContext
if err := yaml.Unmarshal(rawBytes, &qd); err != nil {
if strings.Contains(err.Error(), "failed to unmarshal context from yaml") {
return fmt.Errorf("fix the `context:` block syntax (check tabs/indentation): %w", err)
}
return err
} Prevention
- Use spaces, never tabs, in YAML context blocks.
- Run yamllint on the toolbox config before deploying.
- Keep context snippets in sync with current cloud-gda docs.
When it happens
Trigger: A QueryDataContext node in YAML (e.g. a cloud-gda tool's context field) containing tabs for indentation, unbalanced quotes/brackets, or other invalid YAML passed through yaml.Unmarshal(b, &raw).
Common situations: Hand-editing the context block and breaking indentation; pasting JSON with duplicate keys or trailing commas then editing; editors inserting tabs instead of spaces.
Related errors
- cannot unmarshal %T into StringOrStringSlice
- failed to unmarshal context to proto: %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/46929a05bbba6a1a.
Report an issue: GitHub.