Skip to content

Commit 13a5de7

Browse files
authored
feat: send version in User-Agent header and MCP clientInfo (#12)
Pass the build-time Version to the MCP client so it is included in the User-Agent header and the initialize handshake clientInfo.
1 parent 238712b commit 13a5de7

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎cmd/debug.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func newGoogleAdsMCPClient() (*client.Client, error) {
248248
if err != nil {
249249
return nil, err
250250
}
251-
c := client.New(apiURL, token)
251+
c := client.New(apiURL, token, Version)
252252
fmt.Fprintf(os.Stderr, "Connecting to %s/%s...\n", apiURL, googleAdsMCPServer)
253253
if err := c.Initialize(googleAdsMCPServer); err != nil {
254254
return nil, fmt.Errorf("MCP handshake failed: %w", err)

‎cmd/dynamic.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func runDynamicTool(server ServerConfig, toolName string, schema InputSchema, st
195195
return err
196196
}
197197

198-
c := client.New(apiURL, token)
198+
c := client.New(apiURL, token, Version)
199199

200200
fmt.Fprintf(os.Stderr, "Connecting to %s/%s...\n", apiURL, server.Path)
201201
if err := c.Initialize(server.Path); err != nil {

‎cmd/mcp.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newMCPClient() (*client.Client, error) {
6161
if err != nil {
6262
return nil, err
6363
}
64-
return client.New(apiURL, token), nil
64+
return client.New(apiURL, token, Version), nil
6565
}
6666

6767
func runMCPToolsList(cmd *cobra.Command, args []string) error {

‎cmd/refresh.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func runRefresh(cmd *cobra.Command, args []string) error {
5555
// fetchAndCacheTools fetches tools from all servers and saves the cache.
5656
// If verbose is true, progress is printed to stderr.
5757
func fetchAndCacheTools(baseURL, token string, verbose bool) (*ToolsCache, error) {
58-
c := client.New(baseURL, token)
58+
c := client.New(baseURL, token, Version)
5959
cache := &ToolsCache{
6060
Servers: make(map[string]ServerToolsCache),
6161
UpdatedAt: time.Now(),

‎internal/client/mcp.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ import (
1414
type Client struct {
1515
baseURL string
1616
token string
17+
version string
18+
userAgent string
1719
httpClient *http.Client
1820
reqID atomic.Int64
1921
}
2022

21-
// New creates an MCP client.
22-
func New(baseURL, token string) *Client {
23+
// New creates an MCP client. version is used in the User-Agent header
24+
// and the MCP clientInfo.
25+
func New(baseURL, token, version string) *Client {
2326
return &Client{
2427
baseURL: baseURL,
2528
token: token,
29+
version: version,
30+
userAgent: "pipeboard-cli/" + version,
2631
httpClient: &http.Client{},
2732
}
2833
}
@@ -71,7 +76,7 @@ func (c *Client) Initialize(serverPath string) error {
7176
"capabilities": map[string]interface{}{},
7277
"clientInfo": map[string]string{
7378
"name": "pipeboard-cli",
74-
"version": "0.1.0",
79+
"version": c.version,
7580
},
7681
}
7782

@@ -137,6 +142,7 @@ func (c *Client) call(serverPath, method string, params interface{}) (json.RawMe
137142

138143
httpReq.Header.Set("Content-Type", "application/json")
139144
httpReq.Header.Set("Authorization", "Bearer "+c.token)
145+
httpReq.Header.Set("User-Agent", c.userAgent)
140146

141147
resp, err := c.httpClient.Do(httpReq)
142148
if err != nil {
@@ -218,6 +224,7 @@ func (c *Client) notify(serverPath, method string, params interface{}) error {
218224

219225
httpReq.Header.Set("Content-Type", "application/json")
220226
httpReq.Header.Set("Authorization", "Bearer "+c.token)
227+
httpReq.Header.Set("User-Agent", c.userAgent)
221228

222229
resp, err := c.httpClient.Do(httpReq)
223230
if err != nil {

0 commit comments

Comments
 (0)