googleapis/mcp-toolbox · error
unable to parse as %q: %w
Error message
unable to parse as %q: %w
What it means
The strict decoder rejected the embedding model config body: dec.DecodeContext into gemini.Config failed. This typically means an unknown field (strict mode), a wrong-typed field, or a missing required field inside the embedding model entry.
Source
Thrown at internal/server/config.go:451
return nil, fmt.Errorf("%s is not a valid type of auth service", resourceType)
}
}
func UnmarshalYAMLEmbeddingModelConfig(ctx context.Context, name string, r map[string]any) (embeddingmodels.EmbeddingModelConfig, error) {
resourceType, ok := r["type"].(string)
if !ok {
return nil, fmt.Errorf("missing 'type' field or it is not a string")
}
if resourceType != gemini.EmbeddingModelType {
return nil, fmt.Errorf("%s is not a valid type of embedding model", resourceType)
}
dec, err := util.NewStrictDecoder(r)
if err != nil {
return nil, fmt.Errorf("error creating decoder: %s", err)
}
actual := gemini.Config{Name: name}
if err := dec.DecodeContext(ctx, &actual); err != nil {
return nil, fmt.Errorf("unable to parse as %q: %w", name, err)
}
return actual, nil
}
func UnmarshalYAMLToolConfig(ctx context.Context, name string, r map[string]any) (tools.ToolConfig, error) {
err := NameValidation(name)
if err != nil {
return nil, err
}
resourceType, ok := r["type"].(string)
if !ok {
return nil, fmt.Errorf("missing 'type' field or it is not a string")
}
// `authRequired` and `useClientOAuth` cannot be specified together
if r["authRequired"] != nil && r["useClientOAuth"] == true {
return nil, fmt.Errorf("`authRequired` and `useClientOAuth` are mutually exclusive. Choose only one authentication method")
}
// Make `authRequired` an empty list instead of nil for Tool manifestView on GitHub (pinned to 8cc6e09de2)
Solutions
- Read the wrapped error after 'unable to parse as' for the exact offending field
- Remove or rename unknown/misspelled fields — decoding is strict
- Compare against the documented gemini embedding model example config
Example fix
// before
embeddingModels:
my-embed:
type: gemini
modle: text-embedding-004
// after
embeddingModels:
my-embed:
type: gemini
model: text-embedding-004 Defensive patterns
Strategy: validation
Validate before calling
allowed := map[string]bool{"type": true, "name": true, "model": true, "apiVersion": true, "description": true}
func checkUnknownFields(cfg map[string]any, allowed map[string]bool) []string {
var bad []string
for k := range cfg { if !allowed[k] { bad = append(bad, k) } }
return bad
} Try / catch
cfg, err := server.UnmarshalYAMLEmbeddingModelConfig(ctx, name, raw)
if err != nil {
log.Printf("gemini embedding model %q rejected: %v — check for unknown/misspelled fields", name, err)
return err
} Prevention
- Decoding is strict: remove any field not in the gemini embedding model schema
- Match field-name casing exactly (apiVersion, not apiversion)
- Validate config against the documented example before startup
When it happens
Trigger: An embeddingModels entry with `type: gemini` but containing an unrecognized key (strict decoding), a field of the wrong type (e.g. apiVersion: 2), or a required gemini.Config field that failed validation.
Common situations: Typos in field names like `apiVersion` -> `apiversion`; pasting LLM-model fields (temperature, etc.) that do not exist on the embedding model config; wrong indentation making a sibling key part of the model entry.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- 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
- %s missing 'kind' field or it is not a string
- missing 'kind' field or it is not a string: %v
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/6d58572938b1a157.
Report an issue: GitHub.