Skip to content

Commit 9dacf70

Browse files
chore: extend user agent
1 parent 6c05b40 commit 9dacf70

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/github-mcp-server/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
iolog "github.com/github/github-mcp-server/pkg/log"
1414
"github.com/github/github-mcp-server/pkg/translations"
1515
gogithub "github.com/google/go-github/v69/github"
16+
"github.com/mark3labs/mcp-go/mcp"
1617
"github.com/mark3labs/mcp-go/server"
1718
log "github.com/sirupsen/logrus"
1819
"github.com/spf13/cobra"
@@ -137,11 +138,19 @@ func runStdioServer(cfg runConfig) error {
137138

138139
t, dumpTranslations := translations.TranslationHelper()
139140

141+
beforeInit := func(_ context.Context, _ any, message *mcp.InitializeRequest) {
142+
ghClient.UserAgent = fmt.Sprintf("github-mcp-server/%s (%s/%s)", version, message.Params.ClientInfo.Name, message.Params.ClientInfo.Version)
143+
}
144+
140145
getClient := func(_ context.Context) (*gogithub.Client, error) {
141146
return ghClient, nil // closing over client
142147
}
148+
149+
hooks := &server.Hooks{
150+
OnBeforeInitialize: []server.OnBeforeInitializeFunc{beforeInit},
151+
}
143152
// Create
144-
ghServer := github.NewServer(getClient, version, cfg.readOnly, t)
153+
ghServer := github.NewServer(getClient, version, cfg.readOnly, t, server.WithHooks(hooks))
145154
stdioServer := server.NewStdioServer(ghServer)
146155

147156
stdLogger := stdlog.New(cfg.logger.Writer(), "stdioserver", 0)

0 commit comments

Comments
 (0)