googleapis/mcp-toolbox · error
failed to get user agent from context: %w
Error message
failed to get user agent from context: %w
What it means
Error "failed to get user agent from context: %w" thrown in googleapis/mcp-toolbox.
Source
Thrown at internal/embeddingmodels/gemini/gemini.go:106
} else if apiKey != "" {
// Using Gemini API, which uses API Key for authentication.
configs.Backend = genai.BackendGeminiAPI
configs.APIKey = apiKey
l.InfoContext(ctx, "Using Google AI (Gemini API) backend for Gemini embedding")
} else {
// Missing credentials
return nil, fmt.Errorf("missing credentials for Gemini embedding: " +
"For Google AI: Provide 'apiKey' in YAML or set GOOGLE_API_KEY/GEMINI_API_KEY env vars. " +
"For Vertex AI: Provide 'project'/'location' in YAML or via GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars. " +
"See documentation for details: https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/")
}
// Set user agent
ua, err := util.UserAgentFromContext(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get user agent from context: %w", err)
}
configs.HTTPOptions = genai.HTTPOptions{
Headers: http.Header{
"User-Agent": []string{ua},
},
}
// Create new Gemini API client
client, err := genai.NewClient(ctx, configs)
if err != nil {
return nil, fmt.Errorf("unable to create Gemini API client: %w", err)
}
return &EmbeddingModel{
Config: cfg,
Client: client,
}, nil
}View on GitHub (pinned to 8cc6e09de2)
When it happens
Trigger: Thrown at internal/embeddingmodels/gemini/gemini.go:106 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/80494d75083782d7.
Report an issue: GitHub.