diff --git a/cmd/debug.go b/cmd/debug.go index 2948edc..d121a10 100644 --- a/cmd/debug.go +++ b/cmd/debug.go @@ -132,7 +132,7 @@ func runDebugMetaAds(cmd *cobra.Command, args []string) error { body["ad_account_id"] = debugMetaAdAccountID } - c := client.NewREST(getWebAPIURL(), token) + c := client.NewREST(getWebAPIURL(), token, Version) result, err := c.Post("/api/debug/meta-ads", body) if err != nil { return fmt.Errorf("debug query failed: %w", err) diff --git a/cmd/dynamic.go b/cmd/dynamic.go index a21c29d..4317d77 100644 --- a/cmd/dynamic.go +++ b/cmd/dynamic.go @@ -79,7 +79,7 @@ func maybeAutoRefresh(cache *ToolsCache) { func runAutoRefresh(baseURL, token string) error { cache, _ := loadToolsCache() - hashResult, err := client.FetchToolsHash(baseURL) + hashResult, err := client.FetchToolsHash(baseURL, Version) if err != nil { return err } diff --git a/cmd/refresh.go b/cmd/refresh.go index adaffcd..c5701ba 100644 --- a/cmd/refresh.go +++ b/cmd/refresh.go @@ -89,7 +89,7 @@ func fetchAndCacheTools(baseURL, token string, verbose bool) (*ToolsCache, error } // Fetch and store the current hash - if hashResult, err := client.FetchToolsHash(baseURL); err == nil { + if hashResult, err := client.FetchToolsHash(baseURL, Version); err == nil { cache.Hash = hashResult.Hash } diff --git a/internal/client/mcp.go b/internal/client/mcp.go index 7d56677..5da0ad5 100644 --- a/internal/client/mcp.go +++ b/internal/client/mcp.go @@ -179,8 +179,14 @@ type ToolsHashResult struct { // FetchToolsHash retrieves the combined tools hash from the server. // baseURL is the MCP base URL (e.g. https://mcp.pipeboard.co). // This endpoint requires no authentication. -func FetchToolsHash(baseURL string) (*ToolsHashResult, error) { - resp, err := http.Get(baseURL + "/api/tools-hash") +func FetchToolsHash(baseURL, version string) (*ToolsHashResult, error) { + req, err := http.NewRequest("GET", baseURL+"/api/tools-hash", nil) + if err != nil { + return nil, fmt.Errorf("creating request: %w", err) + } + req.Header.Set("User-Agent", "pipeboard-cli/"+version) + + resp, err := http.DefaultClient.Do(req) if err != nil { return nil, fmt.Errorf("fetching tools hash: %w", err) } diff --git a/internal/client/rest.go b/internal/client/rest.go index 1f39625..b23d108 100644 --- a/internal/client/rest.go +++ b/internal/client/rest.go @@ -12,14 +12,16 @@ import ( type RESTClient struct { baseURL string token string + userAgent string httpClient *http.Client } -// NewREST creates a REST API client. -func NewREST(baseURL, token string) *RESTClient { +// NewREST creates a REST API client. version is used in the User-Agent header. +func NewREST(baseURL, token, version string) *RESTClient { return &RESTClient{ baseURL: baseURL, token: token, + userAgent: "pipeboard-cli/" + version, httpClient: &http.Client{}, } } @@ -39,6 +41,7 @@ func (c *RESTClient) Post(path string, body interface{}) (map[string]interface{} req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+c.token) + req.Header.Set("User-Agent", c.userAgent) resp, err := c.httpClient.Do(req) if err != nil {