@@ -47,6 +47,9 @@ type Client struct {
47
47
48
48
// AuthProvider used for authentication
49
49
AuthProvider auth.Provider
50
+
51
+ // UserAgent is the User-Agent header string sent with requests
52
+ UserAgent string
50
53
}
51
54
52
55
type service struct {
@@ -64,16 +67,25 @@ func defaultHTTPClient(timeout ...time.Duration) *http.Client {
64
67
}
65
68
}
66
69
67
- // NewWithToken creates a new client with the specified base URL and API token
68
- func NewWithAuthProvider (uri string , authProvider auth.Provider , timeout ... time.Duration ) (* Client , error ) {
70
+ // NewWithAuthProvider creates a new client with the specified base URL, auth provider, and optional version
71
+ // If version is an empty string, "unknown" will be used in the User-Agent header
72
+ func NewWithAuthProvider (uri string , authProvider auth.Provider , version string , timeout ... time.Duration ) (* Client , error ) {
69
73
parsedURL , err := url .Parse (uri )
70
74
if err != nil {
71
75
return nil , err
72
76
}
77
+
78
+ versionStr := "unknown"
79
+ if version != "" {
80
+ versionStr = version
81
+ }
82
+ userAgent := fmt .Sprintf ("harness-mcp-client/%s" , versionStr )
83
+
73
84
c := & Client {
74
85
client : defaultHTTPClient (timeout ... ),
75
86
BaseURL : parsedURL ,
76
87
AuthProvider : authProvider ,
88
+ UserAgent : userAgent ,
77
89
}
78
90
return c , nil
79
91
}
@@ -474,6 +486,8 @@ func (c *Client) Do(r *http.Request) (*http.Response, error) {
474
486
}
475
487
r .Header .Set (k , v )
476
488
489
+ r .Header .Set ("User-Agent" , c .UserAgent )
490
+
477
491
// Check for scope in context and add account ID to headers if present
478
492
if scope , err := common .GetScopeFromContext (ctx ); err == nil {
479
493
if scope .AccountID != "" {
0 commit comments