Skip to content

Commit fdf94bd

Browse files
authored
chore: add user agent in requests with mcp version (#58)
1 parent c7d2954 commit fdf94bd

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN nix build .#default
1212

1313
# Final image
1414
# quay.io/sysdig/sysdig-mini-ubi9:1
15-
FROM quay.io/sysdig/sysdig-mini-ubi9@sha256:dcef7a07dc6a8655cbee5e2f3ad7822dea5a0cf4929b1b9effa39e56ce928ca0
15+
FROM quay.io/sysdig/sysdig-mini-ubi9@sha256:fa959bec7353ce38ed2d35190d5ec4445b3c525f1d4ad00e26afca387360a253
1616

1717
# Copy the binary from the builder stage
1818
COPY --from=builder /app/result/bin/sysdig-mcp-server /usr/local/bin/sysdig-mcp-server

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func setupLogger(logLevel string) {
8383

8484
func setupSysdigClient(cfg *config.Config) (sysdig.ExtendedClientWithResponsesInterface, error) {
8585
sysdigClient, err := sysdig.NewSysdigClient(
86+
sysdig.WithVersion(Version),
8687
sysdig.WithFallbackAuthentication(
8788
sysdig.WithHostAndTokenFromContext(),
8889
sysdig.WithFixedHostAndToken(cfg.APIHost, cfg.APIToken),

internal/infra/sysdig/client.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package sysdig
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"net/http"
78
"net/url"
89
)
910

10-
type SysdigAuthentication func(ctx context.Context, req *http.Request) error
11-
1211
type contextKey string
1312

1413
const (
@@ -46,7 +45,7 @@ func updateReqWithHostURL(req *http.Request, host string) error {
4645
return nil
4746
}
4847

49-
func WithFixedHostAndToken(host, apiToken string) SysdigAuthentication {
48+
func WithFixedHostAndToken(host, apiToken string) RequestEditorFn {
5049
return func(ctx context.Context, req *http.Request) error {
5150
if err := updateReqWithHostURL(req, host); err != nil {
5251
return err
@@ -56,7 +55,7 @@ func WithFixedHostAndToken(host, apiToken string) SysdigAuthentication {
5655
}
5756
}
5857

59-
func WithHostAndTokenFromContext() SysdigAuthentication {
58+
func WithHostAndTokenFromContext() RequestEditorFn {
6059
return func(ctx context.Context, req *http.Request) error {
6160
if host, ok := ctx.Value(contextKeyHost).(string); ok && host != "" {
6261
if err := updateReqWithHostURL(req, host); err != nil {
@@ -71,7 +70,7 @@ func WithHostAndTokenFromContext() SysdigAuthentication {
7170
}
7271
}
7372

74-
func WithFallbackAuthentication(auths ...SysdigAuthentication) SysdigAuthentication {
73+
func WithFallbackAuthentication(auths ...RequestEditorFn) RequestEditorFn {
7574
return func(ctx context.Context, req *http.Request) error {
7675
for _, auth := range auths {
7776
if err := auth(ctx, req); err == nil {
@@ -82,10 +81,17 @@ func WithFallbackAuthentication(auths ...SysdigAuthentication) SysdigAuthenticat
8281
}
8382
}
8483

85-
func NewSysdigClient(requestEditors ...SysdigAuthentication) (ExtendedClientWithResponsesInterface, error) {
84+
func WithVersion(version string) RequestEditorFn {
85+
return func(ctx context.Context, req *http.Request) error {
86+
req.Header.Set("User-Agent", fmt.Sprintf("sysdig-mcp-server/%s", version))
87+
return nil
88+
}
89+
}
90+
91+
func NewSysdigClient(requestEditors ...RequestEditorFn) (ExtendedClientWithResponsesInterface, error) {
8692
editors := make([]ClientOption, len(requestEditors))
8793
for i, e := range requestEditors {
88-
editors[i] = WithRequestEditorFn(RequestEditorFn(e))
94+
editors[i] = WithRequestEditorFn(e)
8995
}
9096

9197
return NewClientWithResponses("", editors...)

package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ buildGoModule, versionCheckHook }:
22
buildGoModule (finalAttrs: {
33
pname = "sysdig-mcp-server";
4-
version = "0.5.3";
4+
version = "0.5.4";
55
src = ./.;
66
# This hash is automatically re-calculated with `just rehash-package-nix`. This is automatically called as well by `just bump`.
77
vendorHash = "sha256-jf/px0p88XbfuSPMry/qZcfR0QPTF9IrPegg2CwAd6M=";

0 commit comments

Comments
 (0)