Skip to content

Commit 0ee67b1

Browse files
add a framework for translations
1 parent 031dd74 commit 0ee67b1

14 files changed

+193
-122
lines changed

pkg/github/code_scanning.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/mark3labs/mcp-go/server"
1313
)
1414

15-
func getCodeScanningAlert(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
15+
func getCodeScanningAlert(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1616
return mcp.NewTool("get_code_scanning_alert",
17-
mcp.WithDescription("Get details of a specific code scanning alert in a GitHub repository."),
17+
mcp.WithDescription(t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository.")),
1818
mcp.WithString("owner",
1919
mcp.Required(),
2020
mcp.Description("The owner of the repository."),
@@ -56,9 +56,9 @@ func getCodeScanningAlert(client *github.Client) (tool mcp.Tool, handler server.
5656
}
5757
}
5858

59-
func listCodeScanningAlerts(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
59+
func listCodeScanningAlerts(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6060
return mcp.NewTool("list_code_scanning_alerts",
61-
mcp.WithDescription("List code scanning alerts in a GitHub repository."),
61+
mcp.WithDescription(t("TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION", "List code scanning alerts in a GitHub repository.")),
6262
mcp.WithString("owner",
6363
mcp.Required(),
6464
mcp.Description("The owner of the repository."),

pkg/github/code_scanning_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func Test_GetCodeScanningAlert(t *testing.T) {
1616
// Verify tool definition once
1717
mockClient := github.NewClient(nil)
18-
tool, _ := getCodeScanningAlert(mockClient)
18+
tool, _ := getCodeScanningAlert(mockClient, func(_ string, defaultString string) string { return defaultString })
1919

2020
assert.Equal(t, "get_code_scanning_alert", tool.Name)
2121
assert.NotEmpty(t, tool.Description)
@@ -81,7 +81,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
8181
t.Run(tc.name, func(t *testing.T) {
8282
// Setup client with mock
8383
client := github.NewClient(tc.mockedClient)
84-
_, handler := getCodeScanningAlert(client)
84+
_, handler := getCodeScanningAlert(client, func(_ string, defaultString string) string { return defaultString })
8585

8686
// Create call request
8787
request := createMCPRequest(tc.requestArgs)
@@ -117,7 +117,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
117117
func Test_ListCodeScanningAlerts(t *testing.T) {
118118
// Verify tool definition once
119119
mockClient := github.NewClient(nil)
120-
tool, _ := listCodeScanningAlerts(mockClient)
120+
tool, _ := listCodeScanningAlerts(mockClient, func(_ string, defaultString string) string { return defaultString })
121121

122122
assert.Equal(t, "list_code_scanning_alerts", tool.Name)
123123
assert.NotEmpty(t, tool.Description)
@@ -194,7 +194,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
194194
t.Run(tc.name, func(t *testing.T) {
195195
// Setup client with mock
196196
client := github.NewClient(tc.mockedClient)
197-
_, handler := listCodeScanningAlerts(client)
197+
_, handler := listCodeScanningAlerts(client, func(_ string, defaultString string) string { return defaultString })
198198

199199
// Create call request
200200
request := createMCPRequest(tc.requestArgs)

pkg/github/issues.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
)
1414

1515
// getIssue creates a tool to get details of a specific issue in a GitHub repository.
16-
func getIssue(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
func getIssue(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1717
return mcp.NewTool("get_issue",
18-
mcp.WithDescription("Get details of a specific issue in a GitHub repository."),
18+
mcp.WithDescription(t("TOOL_GET_ISSUE_DESCRIPTION", "Get details of a specific issue in a GitHub repository.")),
1919
mcp.WithString("owner",
2020
mcp.Required(),
2121
mcp.Description("The owner of the repository."),
@@ -58,9 +58,9 @@ func getIssue(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerF
5858
}
5959

6060
// addIssueComment creates a tool to add a comment to an issue.
61-
func addIssueComment(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
61+
func addIssueComment(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6262
return mcp.NewTool("add_issue_comment",
63-
mcp.WithDescription("Add a comment to an existing issue"),
63+
mcp.WithDescription(t("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION", "Add a comment to an existing issue")),
6464
mcp.WithString("owner",
6565
mcp.Required(),
6666
mcp.Description("Repository owner"),
@@ -112,9 +112,9 @@ func addIssueComment(client *github.Client) (tool mcp.Tool, handler server.ToolH
112112
}
113113

114114
// searchIssues creates a tool to search for issues and pull requests.
115-
func searchIssues(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
115+
func searchIssues(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
116116
return mcp.NewTool("search_issues",
117-
mcp.WithDescription("Search for issues and pull requests across GitHub repositories"),
117+
mcp.WithDescription(t("TOOL_SEARCH_ISSUES_DESCRIPTION", "Search for issues and pull requests across GitHub repositories")),
118118
mcp.WithString("q",
119119
mcp.Required(),
120120
mcp.Description("Search query using GitHub issues search syntax"),

pkg/github/issues_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func Test_GetIssue(t *testing.T) {
1717
// Verify tool definition once
1818
mockClient := github.NewClient(nil)
19-
tool, _ := getIssue(mockClient)
19+
tool, _ := getIssue(mockClient, func(_ string, defaultString string) string { return defaultString })
2020

2121
assert.Equal(t, "get_issue", tool.Name)
2222
assert.NotEmpty(t, tool.Description)
@@ -80,7 +80,7 @@ func Test_GetIssue(t *testing.T) {
8080
t.Run(tc.name, func(t *testing.T) {
8181
// Setup client with mock
8282
client := github.NewClient(tc.mockedClient)
83-
_, handler := getIssue(client)
83+
_, handler := getIssue(client, func(_ string, defaultString string) string { return defaultString })
8484

8585
// Create call request
8686
request := createMCPRequest(tc.requestArgs)
@@ -112,7 +112,7 @@ func Test_GetIssue(t *testing.T) {
112112
func Test_AddIssueComment(t *testing.T) {
113113
// Verify tool definition once
114114
mockClient := github.NewClient(nil)
115-
tool, _ := addIssueComment(mockClient)
115+
tool, _ := addIssueComment(mockClient, func(_ string, defaultString string) string { return defaultString })
116116

117117
assert.Equal(t, "add_issue_comment", tool.Name)
118118
assert.NotEmpty(t, tool.Description)
@@ -183,7 +183,7 @@ func Test_AddIssueComment(t *testing.T) {
183183
t.Run(tc.name, func(t *testing.T) {
184184
// Setup client with mock
185185
client := github.NewClient(tc.mockedClient)
186-
_, handler := addIssueComment(client)
186+
_, handler := addIssueComment(client, func(_ string, defaultString string) string { return defaultString })
187187

188188
// Create call request
189189
request := mcp.CallToolRequest{
@@ -228,7 +228,7 @@ func Test_AddIssueComment(t *testing.T) {
228228
func Test_SearchIssues(t *testing.T) {
229229
// Verify tool definition once
230230
mockClient := github.NewClient(nil)
231-
tool, _ := searchIssues(mockClient)
231+
tool, _ := searchIssues(mockClient, func(_ string, defaultString string) string { return defaultString })
232232

233233
assert.Equal(t, "search_issues", tool.Name)
234234
assert.NotEmpty(t, tool.Description)
@@ -332,7 +332,7 @@ func Test_SearchIssues(t *testing.T) {
332332
t.Run(tc.name, func(t *testing.T) {
333333
// Setup client with mock
334334
client := github.NewClient(tc.mockedClient)
335-
_, handler := searchIssues(client)
335+
_, handler := searchIssues(client, func(_ string, defaultString string) string { return defaultString })
336336

337337
// Create call request
338338
request := createMCPRequest(tc.requestArgs)

pkg/github/pullrequests.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
)
1414

1515
// getPullRequest creates a tool to get details of a specific pull request.
16-
func getPullRequest(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
func getPullRequest(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1717
return mcp.NewTool("get_pull_request",
18-
mcp.WithDescription("Get details of a specific pull request"),
18+
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_DESCRIPTION", "Get details of a specific pull request")),
1919
mcp.WithString("owner",
2020
mcp.Required(),
2121
mcp.Description("Repository owner"),
@@ -58,9 +58,9 @@ func getPullRequest(client *github.Client) (tool mcp.Tool, handler server.ToolHa
5858
}
5959

6060
// listPullRequests creates a tool to list and filter repository pull requests.
61-
func listPullRequests(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
61+
func listPullRequests(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
6262
return mcp.NewTool("list_pull_requests",
63-
mcp.WithDescription("List and filter repository pull requests"),
63+
mcp.WithDescription(t("TOOL_LIST_PULL_REQUESTS_DESCRIPTION", "List and filter repository pull requests")),
6464
mcp.WithString("owner",
6565
mcp.Required(),
6666
mcp.Description("Repository owner"),
@@ -159,9 +159,9 @@ func listPullRequests(client *github.Client) (tool mcp.Tool, handler server.Tool
159159
}
160160

161161
// mergePullRequest creates a tool to merge a pull request.
162-
func mergePullRequest(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
162+
func mergePullRequest(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
163163
return mcp.NewTool("merge_pull_request",
164-
mcp.WithDescription("Merge a pull request"),
164+
mcp.WithDescription(t("TOOL_MERGE_PULL_REQUEST_DESCRIPTION", "Merge a pull request")),
165165
mcp.WithString("owner",
166166
mcp.Required(),
167167
mcp.Description("Repository owner"),
@@ -230,9 +230,9 @@ func mergePullRequest(client *github.Client) (tool mcp.Tool, handler server.Tool
230230
}
231231

232232
// getPullRequestFiles creates a tool to get the list of files changed in a pull request.
233-
func getPullRequestFiles(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
233+
func getPullRequestFiles(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
234234
return mcp.NewTool("get_pull_request_files",
235-
mcp.WithDescription("Get the list of files changed in a pull request"),
235+
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_FILES_DESCRIPTION", "Get the list of files changed in a pull request")),
236236
mcp.WithString("owner",
237237
mcp.Required(),
238238
mcp.Description("Repository owner"),
@@ -276,9 +276,9 @@ func getPullRequestFiles(client *github.Client) (tool mcp.Tool, handler server.T
276276
}
277277

278278
// getPullRequestStatus creates a tool to get the combined status of all status checks for a pull request.
279-
func getPullRequestStatus(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
279+
func getPullRequestStatus(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
280280
return mcp.NewTool("get_pull_request_status",
281-
mcp.WithDescription("Get the combined status of all status checks for a pull request"),
281+
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_STATUS_DESCRIPTION", "Get the combined status of all status checks for a pull request")),
282282
mcp.WithString("owner",
283283
mcp.Required(),
284284
mcp.Description("Repository owner"),
@@ -337,9 +337,9 @@ func getPullRequestStatus(client *github.Client) (tool mcp.Tool, handler server.
337337
}
338338

339339
// updatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch.
340-
func updatePullRequestBranch(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
340+
func updatePullRequestBranch(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
341341
return mcp.NewTool("update_pull_request_branch",
342-
mcp.WithDescription("Update a pull request branch with the latest changes from the base branch"),
342+
mcp.WithDescription(t("TOOL_UPDATE_PULL_REQUEST_BRANCH_DESCRIPTION", "Update a pull request branch with the latest changes from the base branch")),
343343
mcp.WithString("owner",
344344
mcp.Required(),
345345
mcp.Description("Repository owner"),
@@ -399,9 +399,9 @@ func updatePullRequestBranch(client *github.Client) (tool mcp.Tool, handler serv
399399
}
400400

401401
// getPullRequestComments creates a tool to get the review comments on a pull request.
402-
func getPullRequestComments(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
402+
func getPullRequestComments(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
403403
return mcp.NewTool("get_pull_request_comments",
404-
mcp.WithDescription("Get the review comments on a pull request"),
404+
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_COMMENTS_DESCRIPTION", "Get the review comments on a pull request")),
405405
mcp.WithString("owner",
406406
mcp.Required(),
407407
mcp.Description("Repository owner"),
@@ -450,9 +450,9 @@ func getPullRequestComments(client *github.Client) (tool mcp.Tool, handler serve
450450
}
451451

452452
// getPullRequestReviews creates a tool to get the reviews on a pull request.
453-
func getPullRequestReviews(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
453+
func getPullRequestReviews(client *github.Client, t func(string, string) string) (tool mcp.Tool, handler server.ToolHandlerFunc) {
454454
return mcp.NewTool("get_pull_request_reviews",
455-
mcp.WithDescription("Get the reviews on a pull request"),
455+
mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_REVIEWS_DESCRIPTION", "Get the reviews on a pull request")),
456456
mcp.WithString("owner",
457457
mcp.Required(),
458458
mcp.Description("Repository owner"),

pkg/github/pullrequests_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func Test_GetPullRequest(t *testing.T) {
1717
// Verify tool definition once
1818
mockClient := github.NewClient(nil)
19-
tool, _ := getPullRequest(mockClient)
19+
tool, _ := getPullRequest(mockClient, func(_ string, defaultString string) string { return defaultString })
2020

2121
assert.Equal(t, "get_pull_request", tool.Name)
2222
assert.NotEmpty(t, tool.Description)
@@ -93,7 +93,7 @@ func Test_GetPullRequest(t *testing.T) {
9393
t.Run(tc.name, func(t *testing.T) {
9494
// Setup client with mock
9595
client := github.NewClient(tc.mockedClient)
96-
_, handler := getPullRequest(client)
96+
_, handler := getPullRequest(client, func(_ string, defaultString string) string { return defaultString })
9797

9898
// Create call request
9999
request := createMCPRequest(tc.requestArgs)
@@ -128,7 +128,7 @@ func Test_GetPullRequest(t *testing.T) {
128128
func Test_ListPullRequests(t *testing.T) {
129129
// Verify tool definition once
130130
mockClient := github.NewClient(nil)
131-
tool, _ := listPullRequests(mockClient)
131+
tool, _ := listPullRequests(mockClient, func(_ string, defaultString string) string { return defaultString })
132132

133133
assert.Equal(t, "list_pull_requests", tool.Name)
134134
assert.NotEmpty(t, tool.Description)
@@ -212,7 +212,7 @@ func Test_ListPullRequests(t *testing.T) {
212212
t.Run(tc.name, func(t *testing.T) {
213213
// Setup client with mock
214214
client := github.NewClient(tc.mockedClient)
215-
_, handler := listPullRequests(client)
215+
_, handler := listPullRequests(client, func(_ string, defaultString string) string { return defaultString })
216216

217217
// Create call request
218218
request := createMCPRequest(tc.requestArgs)
@@ -250,7 +250,7 @@ func Test_ListPullRequests(t *testing.T) {
250250
func Test_MergePullRequest(t *testing.T) {
251251
// Verify tool definition once
252252
mockClient := github.NewClient(nil)
253-
tool, _ := mergePullRequest(mockClient)
253+
tool, _ := mergePullRequest(mockClient, func(_ string, defaultString string) string { return defaultString })
254254

255255
assert.Equal(t, "merge_pull_request", tool.Name)
256256
assert.NotEmpty(t, tool.Description)
@@ -321,7 +321,7 @@ func Test_MergePullRequest(t *testing.T) {
321321
t.Run(tc.name, func(t *testing.T) {
322322
// Setup client with mock
323323
client := github.NewClient(tc.mockedClient)
324-
_, handler := mergePullRequest(client)
324+
_, handler := mergePullRequest(client, func(_ string, defaultString string) string { return defaultString })
325325

326326
// Create call request
327327
request := createMCPRequest(tc.requestArgs)
@@ -355,7 +355,7 @@ func Test_MergePullRequest(t *testing.T) {
355355
func Test_GetPullRequestFiles(t *testing.T) {
356356
// Verify tool definition once
357357
mockClient := github.NewClient(nil)
358-
tool, _ := getPullRequestFiles(mockClient)
358+
tool, _ := getPullRequestFiles(mockClient, func(_ string, defaultString string) string { return defaultString })
359359

360360
assert.Equal(t, "get_pull_request_files", tool.Name)
361361
assert.NotEmpty(t, tool.Description)
@@ -433,7 +433,7 @@ func Test_GetPullRequestFiles(t *testing.T) {
433433
t.Run(tc.name, func(t *testing.T) {
434434
// Setup client with mock
435435
client := github.NewClient(tc.mockedClient)
436-
_, handler := getPullRequestFiles(client)
436+
_, handler := getPullRequestFiles(client, func(_ string, defaultString string) string { return defaultString })
437437

438438
// Create call request
439439
request := createMCPRequest(tc.requestArgs)
@@ -471,7 +471,7 @@ func Test_GetPullRequestFiles(t *testing.T) {
471471
func Test_GetPullRequestStatus(t *testing.T) {
472472
// Verify tool definition once
473473
mockClient := github.NewClient(nil)
474-
tool, _ := getPullRequestStatus(mockClient)
474+
tool, _ := getPullRequestStatus(mockClient, func(_ string, defaultString string) string { return defaultString })
475475

476476
assert.Equal(t, "get_pull_request_status", tool.Name)
477477
assert.NotEmpty(t, tool.Description)
@@ -593,7 +593,7 @@ func Test_GetPullRequestStatus(t *testing.T) {
593593
t.Run(tc.name, func(t *testing.T) {
594594
// Setup client with mock
595595
client := github.NewClient(tc.mockedClient)
596-
_, handler := getPullRequestStatus(client)
596+
_, handler := getPullRequestStatus(client, func(_ string, defaultString string) string { return defaultString })
597597

598598
// Create call request
599599
request := createMCPRequest(tc.requestArgs)
@@ -632,7 +632,7 @@ func Test_GetPullRequestStatus(t *testing.T) {
632632
func Test_UpdatePullRequestBranch(t *testing.T) {
633633
// Verify tool definition once
634634
mockClient := github.NewClient(nil)
635-
tool, _ := updatePullRequestBranch(mockClient)
635+
tool, _ := updatePullRequestBranch(mockClient, func(_ string, defaultString string) string { return defaultString })
636636

637637
assert.Equal(t, "update_pull_request_branch", tool.Name)
638638
assert.NotEmpty(t, tool.Description)
@@ -714,7 +714,7 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
714714
t.Run(tc.name, func(t *testing.T) {
715715
// Setup client with mock
716716
client := github.NewClient(tc.mockedClient)
717-
_, handler := updatePullRequestBranch(client)
717+
_, handler := updatePullRequestBranch(client, func(_ string, defaultString string) string { return defaultString })
718718

719719
// Create call request
720720
request := createMCPRequest(tc.requestArgs)
@@ -742,7 +742,7 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
742742
func Test_GetPullRequestComments(t *testing.T) {
743743
// Verify tool definition once
744744
mockClient := github.NewClient(nil)
745-
tool, _ := getPullRequestComments(mockClient)
745+
tool, _ := getPullRequestComments(mockClient, func(_ string, defaultString string) string { return defaultString })
746746

747747
assert.Equal(t, "get_pull_request_comments", tool.Name)
748748
assert.NotEmpty(t, tool.Description)
@@ -830,7 +830,7 @@ func Test_GetPullRequestComments(t *testing.T) {
830830
t.Run(tc.name, func(t *testing.T) {
831831
// Setup client with mock
832832
client := github.NewClient(tc.mockedClient)
833-
_, handler := getPullRequestComments(client)
833+
_, handler := getPullRequestComments(client, func(_ string, defaultString string) string { return defaultString })
834834

835835
// Create call request
836836
request := createMCPRequest(tc.requestArgs)
@@ -869,7 +869,7 @@ func Test_GetPullRequestComments(t *testing.T) {
869869
func Test_GetPullRequestReviews(t *testing.T) {
870870
// Verify tool definition once
871871
mockClient := github.NewClient(nil)
872-
tool, _ := getPullRequestReviews(mockClient)
872+
tool, _ := getPullRequestReviews(mockClient, func(_ string, defaultString string) string { return defaultString })
873873

874874
assert.Equal(t, "get_pull_request_reviews", tool.Name)
875875
assert.NotEmpty(t, tool.Description)
@@ -953,7 +953,7 @@ func Test_GetPullRequestReviews(t *testing.T) {
953953
t.Run(tc.name, func(t *testing.T) {
954954
// Setup client with mock
955955
client := github.NewClient(tc.mockedClient)
956-
_, handler := getPullRequestReviews(client)
956+
_, handler := getPullRequestReviews(client, func(_ string, defaultString string) string { return defaultString })
957957

958958
// Create call request
959959
request := createMCPRequest(tc.requestArgs)

0 commit comments

Comments
 (0)