{"record":{"id":"eaba0635827341d8","repo":"googleapis/mcp-toolbox","slug":"error-in-user-agent-retrieval-s-eaba06","errorCode":null,"errorMessage":"error in User Agent retrieval: %s","messagePattern":"error in User Agent retrieval: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dataproc/dataproc.go","lineNumber":69,"sourceCode":"\t}\n\treturn actual, nil\n}\n\ntype Config struct {\n\tName    string `yaml:\"name\" validate:\"required\"`\n\tType    string `yaml:\"type\" validate:\"required\"`\n\tProject string `yaml:\"project\" validate:\"required\"`\n\tRegion  string `yaml:\"region\" validate:\"required\"`\n}\n\nfunc (r Config) SourceConfigType() string {\n\treturn SourceType\n}\n\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {\n\tua, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in User Agent retrieval: %s\", err)\n\t}\n\tendpoint := fmt.Sprintf(\"%s-dataproc.googleapis.com:443\", r.Region)\n\tclient, err := dataproc.NewClusterControllerClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create dataproc client: %w\", err)\n\t}\n\topsClient, err := longrunning.NewOperationsClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\tclient.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create longrunning client: %w\", err)\n\t}\n\tjobClient, err := dataproc.NewJobControllerClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\tclient.Close()\n\t\topsClient.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create dataproc job client: %w\", err)\n\t}\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dataproc/dataproc.go#L51-L87","documentation":"Thrown by the Dataproc source's Config.Initialize when util.UserAgentFromContext cannot extract a User-Agent string from the context. The library requires a User-Agent on every request for telemetry/identification, so initialization is aborted before any GCP client is created.","triggerScenarios":"Initializing the dataproc source with a context that lacks the User-Agent value expected by util.UserAgentFromContext — i.e., the caller did not inject the user agent into the context before calling Initialize.","commonSituations":"Tests or custom harnesses that build a bare context.Context without the toolbox's user-agent injection; calling Initialize programmatically instead of through the standard server request path that attaches the User-Agent.","solutions":["Invoke the source through the standard toolbox request path, which injects the User-Agent into the context.","If calling Initialize directly (e.g., in tests), inject the User-Agent into the context using the same util helper the library uses.","Check the version: if a recent refactor stopped populating the user agent in the context, update or report the calling framework code."],"exampleFix":"// before\nsrc, err := cfg.Initialize(ctx, tracer)\n\n// after: ensure the user agent is present in the context\nctx = util.ContextWithUserAgent(ctx, \"my-app/1.0\")\nsrc, err := cfg.Initialize(ctx, tracer)","handlingStrategy":"validation","validationCode":"// ensure user agent is present before calling Initialize\nctx = util.ContextWithUserAgent(ctx, \"my-client/1.0\")\nif ua, err := util.UserAgentFromContext(ctx); err != nil {\n    return fmt.Errorf(\"context missing user agent: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil {\n    if strings.Contains(err.Error(), \"User Agent retrieval\") {\n        // fix context injection and retry\n    }\n    return err\n}","preventionTips":["Always call Initialize via the standard toolbox request path that injects the User-Agent.","In tests, use the same user-agent context helper the library uses.","Never construct a bare context.Context for source initialization."],"tags":["dataproc","user-agent","context","initialization"],"backgroundTag":"missing-user-agent","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}