Skip to content

Commit 4833cfd

Browse files
wrap the translations export with a flag
1 parent b747344 commit 4833cfd

15 files changed

+103
-81
lines changed

cmd/github-mcp-server/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/github/github-mcp-server/pkg/github"
1313
iolog "github.com/github/github-mcp-server/pkg/log"
14+
"github.com/github/github-mcp-server/pkg/translations"
1415
gogithub "github.com/google/go-github/v69/github"
1516
"github.com/mark3labs/mcp-go/server"
1617
log "github.com/sirupsen/logrus"
@@ -36,7 +37,7 @@ var (
3637
stdlog.Fatal("Failed to initialize logger:", err)
3738
}
3839
logCommands := viper.GetBool("enable-command-logging")
39-
if err := runStdioServer(logger, logCommands); err != nil {
40+
if err := runStdioServer(logger, logCommands, viper.GetBool("export-translations")); err != nil {
4041
stdlog.Fatal("failed to run stdio server:", err)
4142
}
4243
},
@@ -49,10 +50,12 @@ func init() {
4950
// Add global flags that will be shared by all commands
5051
rootCmd.PersistentFlags().String("log-file", "", "Path to log file")
5152
rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
53+
rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
5254

5355
// Bind flag to viper
5456
viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file"))
5557
viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
58+
viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations"))
5659

5760
// Add subcommands
5861
rootCmd.AddCommand(stdioCmd)
@@ -81,7 +84,7 @@ func initLogger(outPath string) (*log.Logger, error) {
8184
return logger, nil
8285
}
8386

84-
func runStdioServer(logger *log.Logger, logCommands bool) error {
87+
func runStdioServer(logger *log.Logger, logCommands bool, exportTranslations bool) error {
8588
// Create app context
8689
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
8790
defer stop()
@@ -93,13 +96,20 @@ func runStdioServer(logger *log.Logger, logCommands bool) error {
9396
}
9497
ghClient := gogithub.NewClient(nil).WithAuthToken(token)
9598

99+
t, dumpTranslations := translations.TranslationHelper()
100+
96101
// Create server
97-
ghServer := github.NewServer(ghClient)
102+
ghServer := github.NewServer(ghClient, t)
98103
stdioServer := server.NewStdioServer(ghServer)
99104

100105
stdLogger := stdlog.New(logger.Writer(), "stdioserver", 0)
101106
stdioServer.SetErrorLogger(stdLogger)
102107

108+
if exportTranslations {
109+
// Once server is initialized, all translations are loaded
110+
dumpTranslations()
111+
}
112+
103113
// Start listening for messages
104114
errC := make(chan error, 1)
105115
go func() {

pkg/github/code_scanning.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"io"
88
"net/http"
99

10+
"github.com/github/github-mcp-server/pkg/translations"
1011
"github.com/google/go-github/v69/github"
1112
"github.com/mark3labs/mcp-go/mcp"
1213
"github.com/mark3labs/mcp-go/server"
1314
)
1415

15-
func getCodeScanningAlert(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
func getCodeScanningAlert(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1617
return mcp.NewTool("get_code_scanning_alert",
1718
mcp.WithDescription(t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository.")),
1819
mcp.WithString("owner",
@@ -56,7 +57,7 @@ func getCodeScanningAlert(client *github.Client, t func(string, string) string)
5657
}
5758
}
5859

59-
func listCodeScanningAlerts(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
60+
func listCodeScanningAlerts(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6061
return mcp.NewTool("list_code_scanning_alerts",
6162
mcp.WithDescription(t("TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION", "List code scanning alerts in a GitHub repository.")),
6263
mcp.WithString("owner",

pkg/github/code_scanning_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"testing"
88

9+
"github.com/github/github-mcp-server/pkg/translations"
910
"github.com/google/go-github/v69/github"
1011
"github.com/migueleliasweb/go-github-mock/src/mock"
1112
"github.com/stretchr/testify/assert"
@@ -15,7 +16,7 @@ import (
1516
func Test_GetCodeScanningAlert(t *testing.T) {
1617
// Verify tool definition once
1718
mockClient := github.NewClient(nil)
18-
tool, _ := getCodeScanningAlert(mockClient, func(_ string, defaultString string) string { return defaultString })
19+
tool, _ := getCodeScanningAlert(mockClient, translations.NullTranslationHelper)
1920

2021
assert.Equal(t, "get_code_scanning_alert", tool.Name)
2122
assert.NotEmpty(t, tool.Description)
@@ -81,7 +82,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
8182
t.Run(tc.name, func(t *testing.T) {
8283
// Setup client with mock
8384
client := github.NewClient(tc.mockedClient)
84-
_, handler := getCodeScanningAlert(client, func(_ string, defaultString string) string { return defaultString })
85+
_, handler := getCodeScanningAlert(client, translations.NullTranslationHelper)
8586

8687
// Create call request
8788
request := createMCPRequest(tc.requestArgs)
@@ -117,7 +118,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
117118
func Test_ListCodeScanningAlerts(t *testing.T) {
118119
// Verify tool definition once
119120
mockClient := github.NewClient(nil)
120-
tool, _ := listCodeScanningAlerts(mockClient, func(_ string, defaultString string) string { return defaultString })
121+
tool, _ := listCodeScanningAlerts(mockClient, translations.NullTranslationHelper)
121122

122123
assert.Equal(t, "list_code_scanning_alerts", tool.Name)
123124
assert.NotEmpty(t, tool.Description)
@@ -194,7 +195,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
194195
t.Run(tc.name, func(t *testing.T) {
195196
// Setup client with mock
196197
client := github.NewClient(tc.mockedClient)
197-
_, handler := listCodeScanningAlerts(client, func(_ string, defaultString string) string { return defaultString })
198+
_, handler := listCodeScanningAlerts(client, translations.NullTranslationHelper)
198199

199200
// Create call request
200201
request := createMCPRequest(tc.requestArgs)

pkg/github/issues.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"io"
88
"net/http"
99

10+
"github.com/github/github-mcp-server/pkg/translations"
1011
"github.com/google/go-github/v69/github"
1112
"github.com/mark3labs/mcp-go/mcp"
1213
"github.com/mark3labs/mcp-go/server"
1314
)
1415

1516
// getIssue creates a tool to get details of a specific issue in a GitHub repository.
16-
func getIssue(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
17+
func getIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1718
return mcp.NewTool("get_issue",
1819
mcp.WithDescription(t("TOOL_GET_ISSUE_DESCRIPTION", "Get details of a specific issue in a GitHub repository.")),
1920
mcp.WithString("owner",
@@ -58,7 +59,7 @@ func getIssue(client *github.Client, t func(string, string) string) (tool mcp.To
5859
}
5960

6061
// addIssueComment creates a tool to add a comment to an issue.
61-
func addIssueComment(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
62+
func addIssueComment(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6263
return mcp.NewTool("add_issue_comment",
6364
mcp.WithDescription(t("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION", "Add a comment to an existing issue")),
6465
mcp.WithString("owner",
@@ -112,7 +113,7 @@ func addIssueComment(client *github.Client, t func(string, string) string) (tool
112113
}
113114

114115
// searchIssues creates a tool to search for issues and pull requests.
115-
func searchIssues(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
116+
func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
116117
return mcp.NewTool("search_issues",
117118
mcp.WithDescription(t("TOOL_SEARCH_ISSUES_DESCRIPTION", "Search for issues and pull requests across GitHub repositories")),
118119
mcp.WithString("q",

pkg/github/issues_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"testing"
88

9+
"github.com/github/github-mcp-server/pkg/translations"
910
"github.com/google/go-github/v69/github"
1011
"github.com/mark3labs/mcp-go/mcp"
1112
"github.com/migueleliasweb/go-github-mock/src/mock"
@@ -16,7 +17,7 @@ import (
1617
func Test_GetIssue(t *testing.T) {
1718
// Verify tool definition once
1819
mockClient := github.NewClient(nil)
19-
tool, _ := getIssue(mockClient, func(_ string, defaultString string) string { return defaultString })
20+
tool, _ := getIssue(mockClient, translations.NullTranslationHelper)
2021

2122
assert.Equal(t, "get_issue", tool.Name)
2223
assert.NotEmpty(t, tool.Description)
@@ -80,7 +81,7 @@ func Test_GetIssue(t *testing.T) {
8081
t.Run(tc.name, func(t *testing.T) {
8182
// Setup client with mock
8283
client := github.NewClient(tc.mockedClient)
83-
_, handler := getIssue(client, func(_ string, defaultString string) string { return defaultString })
84+
_, handler := getIssue(client, translations.NullTranslationHelper)
8485

8586
// Create call request
8687
request := createMCPRequest(tc.requestArgs)
@@ -112,7 +113,7 @@ func Test_GetIssue(t *testing.T) {
112113
func Test_AddIssueComment(t *testing.T) {
113114
// Verify tool definition once
114115
mockClient := github.NewClient(nil)
115-
tool, _ := addIssueComment(mockClient, func(_ string, defaultString string) string { return defaultString })
116+
tool, _ := addIssueComment(mockClient, translations.NullTranslationHelper)
116117

117118
assert.Equal(t, "add_issue_comment", tool.Name)
118119
assert.NotEmpty(t, tool.Description)
@@ -183,7 +184,7 @@ func Test_AddIssueComment(t *testing.T) {
183184
t.Run(tc.name, func(t *testing.T) {
184185
// Setup client with mock
185186
client := github.NewClient(tc.mockedClient)
186-
_, handler := addIssueComment(client, func(_ string, defaultString string) string { return defaultString })
187+
_, handler := addIssueComment(client, translations.NullTranslationHelper)
187188

188189
// Create call request
189190
request := mcp.CallToolRequest{
@@ -228,7 +229,7 @@ func Test_AddIssueComment(t *testing.T) {
228229
func Test_SearchIssues(t *testing.T) {
229230
// Verify tool definition once
230231
mockClient := github.NewClient(nil)
231-
tool, _ := searchIssues(mockClient, func(_ string, defaultString string) string { return defaultString })
232+
tool, _ := searchIssues(mockClient, translations.NullTranslationHelper)
232233

233234
assert.Equal(t, "search_issues", tool.Name)
234235
assert.NotEmpty(t, tool.Description)
@@ -332,7 +333,7 @@ func Test_SearchIssues(t *testing.T) {
332333
t.Run(tc.name, func(t *testing.T) {
333334
// Setup client with mock
334335
client := github.NewClient(tc.mockedClient)
335-
_, handler := searchIssues(client, func(_ string, defaultString string) string { return defaultString })
336+
_, handler := searchIssues(client, translations.NullTranslationHelper)
336337

337338
// Create call request
338339
request := createMCPRequest(tc.requestArgs)

pkg/github/pullrequests.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"io"
88
"net/http"
99

10+
"github.com/github/github-mcp-server/pkg/translations"
1011
"github.com/google/go-github/v69/github"
1112
"github.com/mark3labs/mcp-go/mcp"
1213
"github.com/mark3labs/mcp-go/server"
1314
)
1415

1516
// getPullRequest creates a tool to get details of a specific pull request.
16-
func getPullRequest(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
17+
func getPullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1718
return mcp.NewTool("get_pull_request",
1819
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_DESCRIPTION", "Get details of a specific pull request")),
1920
mcp.WithString("owner",
@@ -58,7 +59,7 @@ func getPullRequest(client *github.Client, t func(string, string) string) (tool
5859
}
5960

6061
// listPullRequests creates a tool to list and filter repository pull requests.
61-
func listPullRequests(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
62+
func listPullRequests(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6263
return mcp.NewTool("list_pull_requests",
6364
mcp.WithDescription(t("TOOL_LIST_PULL_REQUESTS_DESCRIPTION", "List and filter repository pull requests")),
6465
mcp.WithString("owner",
@@ -159,7 +160,7 @@ func listPullRequests(client *github.Client, t func(string, string) string) (too
159160
}
160161

161162
// mergePullRequest creates a tool to merge a pull request.
162-
func mergePullRequest(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
163+
func mergePullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
163164
return mcp.NewTool("merge_pull_request",
164165
mcp.WithDescription(t("TOOL_MERGE_PULL_REQUEST_DESCRIPTION", "Merge a pull request")),
165166
mcp.WithString("owner",
@@ -230,7 +231,7 @@ func mergePullRequest(client *github.Client, t func(string, string) string) (too
230231
}
231232

232233
// getPullRequestFiles creates a tool to get the list of files changed in a pull request.
233-
func getPullRequestFiles(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
234+
func getPullRequestFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
234235
return mcp.NewTool("get_pull_request_files",
235236
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_FILES_DESCRIPTION", "Get the list of files changed in a pull request")),
236237
mcp.WithString("owner",
@@ -276,7 +277,7 @@ func getPullRequestFiles(client *github.Client, t func(string, string) string) (
276277
}
277278

278279
// getPullRequestStatus creates a tool to get the combined status of all status checks for a pull request.
279-
func getPullRequestStatus(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
280+
func getPullRequestStatus(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
280281
return mcp.NewTool("get_pull_request_status",
281282
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_STATUS_DESCRIPTION", "Get the combined status of all status checks for a pull request")),
282283
mcp.WithString("owner",
@@ -337,7 +338,7 @@ func getPullRequestStatus(client *github.Client, t func(string, string) string)
337338
}
338339

339340
// updatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch.
340-
func updatePullRequestBranch(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
341+
func updatePullRequestBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
341342
return mcp.NewTool("update_pull_request_branch",
342343
mcp.WithDescription(t("TOOL_UPDATE_PULL_REQUEST_BRANCH_DESCRIPTION", "Update a pull request branch with the latest changes from the base branch")),
343344
mcp.WithString("owner",
@@ -399,7 +400,7 @@ func updatePullRequestBranch(client *github.Client, t func(string, string) strin
399400
}
400401

401402
// getPullRequestComments creates a tool to get the review comments on a pull request.
402-
func getPullRequestComments(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
403+
func getPullRequestComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
403404
return mcp.NewTool("get_pull_request_comments",
404405
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_COMMENTS_DESCRIPTION", "Get the review comments on a pull request")),
405406
mcp.WithString("owner",
@@ -450,7 +451,7 @@ func getPullRequestComments(client *github.Client, t func(string, string) string
450451
}
451452

452453
// getPullRequestReviews creates a tool to get the reviews on a pull request.
453-
func getPullRequestReviews(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
454+
func getPullRequestReviews(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
454455
return mcp.NewTool("get_pull_request_reviews",
455456
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_REVIEWS_DESCRIPTION", "Get the reviews on a pull request")),
456457
mcp.WithString("owner",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy