googleapis/mcp-toolbox · error

error in User Agent retrieval: %s

Error message

error in User Agent retrieval: %s

What it means

CloudGDA's Initialize extracts a user-agent string from the context via util.UserAgentFromContext and fails fast if retrieval errors. The user agent is required to build the Gemini Data Analytics client, so initialization cannot proceed without it.

Source

Thrown at internal/sources/cloudgda/cloud_gda.go:69

	return actual, nil
}

type Config struct {
	Name           string `yaml:"name" validate:"required"`
	Type           string `yaml:"type" validate:"required"`
	ProjectID      string `yaml:"projectId" validate:"required"`
	UseClientOAuth bool   `yaml:"useClientOAuth"`
}

func (r Config) SourceConfigType() string {
	return SourceType
}

// Initialize initializes a Gemini Data Analytics Source instance.
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
	ua, err := util.UserAgentFromContext(ctx)
	if err != nil {
		return nil, fmt.Errorf("error in User Agent retrieval: %s", err)
	}

	s := &Source{
		Config:    r,
		userAgent: ua,
	}

	if !r.UseClientOAuth {
		client, err := NewDataChatClient(ctx, option.WithUserAgent(ua))
		if err != nil {
			return nil, fmt.Errorf("failed to create DataChatClient: %w", err)
		}
		s.Client = client
	}

	return s, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Ensure the context passed to Initialize carries the user agent expected by util.UserAgentFromContext (use the library's context-annotation helpers)
  2. Use the standard toolbox request path, which injects the user agent automatically
  3. Check the wrapped message (%s) for the exact retrieval failure

Example fix

// before
src, err := cfg.Initialize(context.Background(), tracer)
// after
ctx := util.WithUserAgent(context.Background(), "toolbox/1.0")
src, err := cfg.Initialize(ctx, tracer)
Defensive patterns

Strategy: validation

Validate before calling

// ensure the context carries a user agent before Initialize
func hasUserAgent(ctx context.Context) bool {
    _, err := util.UserAgentFromContext(ctx)
    return err == nil
}

Prevention

When it happens

Trigger: Creating a cloudgda source whose Initialize receives a context lacking the required user-agent value that util.UserAgentFromContext expects (missing/invalid user agent entry in ctx).

Common situations: Programmatic setups that construct a bare context.Context without populating the user agent, or unit/integration tests calling Initialize directly with context.Background().

Related errors


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