Skip to content

Commit 9d71184

Browse files
chrisarcandclaude
andauthored
Set custom User-Agent for TFE API requests (#268)
This change sets a custom User-Agent header ("terraform-mcp-server/{version}") for all Terraform Cloud/Enterprise API requests made by the MCP server. Previously, the MCP server used the default go-tfe User-Agent ("go-tfe"), making it impossible to distinguish MCP server requests from other go-tfe client requests in HCP Terraform logs and metrics. With this change: - TFE API requests will use: "terraform-mcp-server/{version}" - This matches the pattern already used for Registry API requests - HCP Terraform can now identify and track MCP server usage separately Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent 865332b commit 9d71184

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## UNRELEASED
2+
3+
IMPROVEMENTS
4+
5+
* Set custom User-Agent header for TFE API requests to enable tracking MCP server usage separately from other go-tfe clients [268](https://github.com/hashicorp/terraform-mcp-server/pull/268)
6+
17
## 0.4.0
28

39
FEATURES

pkg/client/tfe_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package client
66
import (
77
"context"
88
"fmt"
9+
"net/http"
910
"sync"
1011

1112
"github.com/hashicorp/go-tfe"
1213
"github.com/hashicorp/terraform-mcp-server/pkg/utils"
14+
"github.com/hashicorp/terraform-mcp-server/version"
1315
"github.com/mark3labs/mcp-go/server"
1416
log "github.com/sirupsen/logrus"
1517
)
@@ -34,8 +36,10 @@ func NewTfeClient(sessionId string, terraformAddress string, terraformSkipTLSVer
3436
Address: terraformAddress,
3537
Token: terraformToken,
3638
RetryServerErrors: true,
39+
Headers: make(http.Header),
3740
}
3841

42+
config.Headers.Set("User-Agent", fmt.Sprintf("terraform-mcp-server/%s", version.GetHumanVersion()))
3943
config.HTTPClient = createHTTPClient(terraformSkipTLSVerify, logger)
4044

4145
client, err := tfe.NewClient(config)

0 commit comments

Comments
 (0)