From e10f392c2ac06291e964448b4bc5a594f55d812a Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Mon, 7 Apr 2025 23:07:56 +0200 Subject: [PATCH 1/5] chore: export code scanning funcs --- pkg/github/code_scanning.go | 4 ++-- pkg/github/code_scanning_test.go | 8 ++++---- pkg/github/server.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/github/code_scanning.go b/pkg/github/code_scanning.go index 81ee2c31..1b9cd876 100644 --- a/pkg/github/code_scanning.go +++ b/pkg/github/code_scanning.go @@ -13,7 +13,7 @@ import ( "github.com/mark3labs/mcp-go/server" ) -func getCodeScanningAlert(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +func GetCodeScanningAlert(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_code_scanning_alert", mcp.WithDescription(t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository.")), mcp.WithString("owner", @@ -66,7 +66,7 @@ func getCodeScanningAlert(client *github.Client, t translations.TranslationHelpe } } -func listCodeScanningAlerts(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +func ListCodeScanningAlerts(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_code_scanning_alerts", mcp.WithDescription(t("TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION", "List code scanning alerts in a GitHub repository.")), mcp.WithString("owner", diff --git a/pkg/github/code_scanning_test.go b/pkg/github/code_scanning_test.go index ec4d671e..f1f3a1de 100644 --- a/pkg/github/code_scanning_test.go +++ b/pkg/github/code_scanning_test.go @@ -16,7 +16,7 @@ import ( func Test_GetCodeScanningAlert(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getCodeScanningAlert(mockClient, translations.NullTranslationHelper) + tool, _ := GetCodeScanningAlert(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_code_scanning_alert", tool.Name) assert.NotEmpty(t, tool.Description) @@ -82,7 +82,7 @@ func Test_GetCodeScanningAlert(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getCodeScanningAlert(client, translations.NullTranslationHelper) + _, handler := GetCodeScanningAlert(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -118,7 +118,7 @@ func Test_GetCodeScanningAlert(t *testing.T) { func Test_ListCodeScanningAlerts(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := listCodeScanningAlerts(mockClient, translations.NullTranslationHelper) + tool, _ := ListCodeScanningAlerts(mockClient, translations.NullTranslationHelper) assert.Equal(t, "list_code_scanning_alerts", tool.Name) assert.NotEmpty(t, tool.Description) @@ -201,7 +201,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := listCodeScanningAlerts(client, translations.NullTranslationHelper) + _, handler := ListCodeScanningAlerts(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) diff --git a/pkg/github/server.go b/pkg/github/server.go index bf3583b9..ec485a74 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -75,8 +75,8 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati s.AddTool(getMe(client, t)) // Add GitHub tools - Code Scanning - s.AddTool(getCodeScanningAlert(client, t)) - s.AddTool(listCodeScanningAlerts(client, t)) + s.AddTool(GetCodeScanningAlert(client, t)) + s.AddTool(ListCodeScanningAlerts(client, t)) return s } From a2208abbca50a36480550a48291a476b3f5c2e57 Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Mon, 7 Apr 2025 23:22:56 +0200 Subject: [PATCH 2/5] chore: export issues funcs --- pkg/github/issues.go | 28 ++++++++++++++-------------- pkg/github/issues_test.go | 28 ++++++++++++++-------------- pkg/github/server.go | 14 +++++++------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 1632e9e8..8b1039ca 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -14,8 +14,8 @@ import ( "github.com/mark3labs/mcp-go/server" ) -// getIssue creates a tool to get details of a specific issue in a GitHub repository. -func getIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetIssue creates a tool to get details of a specific issue in a GitHub repository. +func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_issue", mcp.WithDescription(t("TOOL_GET_ISSUE_DESCRIPTION", "Get details of a specific issue in a GitHub repository.")), mcp.WithString("owner", @@ -68,8 +68,8 @@ func getIssue(client *github.Client, t translations.TranslationHelperFunc) (tool } } -// addIssueComment creates a tool to add a comment to an issue. -func addIssueComment(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// AddIssueComment creates a tool to add a comment to an issue. +func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("add_issue_comment", mcp.WithDescription(t("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION", "Add a comment to an existing issue")), mcp.WithString("owner", @@ -134,8 +134,8 @@ func addIssueComment(client *github.Client, t translations.TranslationHelperFunc } } -// searchIssues creates a tool to search for issues and pull requests. -func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// SearchIssues creates a tool to search for issues and pull requests. +func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("search_issues", mcp.WithDescription(t("TOOL_SEARCH_ISSUES_DESCRIPTION", "Search for issues and pull requests across GitHub repositories")), mcp.WithString("q", @@ -214,8 +214,8 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) ( } } -// createIssue creates a tool to create a new issue in a GitHub repository. -func createIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreateIssue creates a tool to create a new issue in a GitHub repository. +func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_issue", mcp.WithDescription(t("TOOL_CREATE_ISSUE_DESCRIPTION", "Create a new issue in a GitHub repository")), mcp.WithString("owner", @@ -328,8 +328,8 @@ func createIssue(client *github.Client, t translations.TranslationHelperFunc) (t } } -// listIssues creates a tool to list and filter repository issues -func listIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// ListIssues creates a tool to list and filter repository issues +func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_issues", mcp.WithDescription(t("TOOL_LIST_ISSUES_DESCRIPTION", "List issues in a GitHub repository with filtering options")), mcp.WithString("owner", @@ -442,8 +442,8 @@ func listIssues(client *github.Client, t translations.TranslationHelperFunc) (to } } -// updateIssue creates a tool to update an existing issue in a GitHub repository. -func updateIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// UpdateIssue creates a tool to update an existing issue in a GitHub repository. +func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("update_issue", mcp.WithDescription(t("TOOL_UPDATE_ISSUE_DESCRIPTION", "Update an existing issue in a GitHub repository")), mcp.WithString("owner", @@ -580,8 +580,8 @@ func updateIssue(client *github.Client, t translations.TranslationHelperFunc) (t } } -// getIssueComments creates a tool to get comments for a GitHub issue. -func getIssueComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetIssueComments creates a tool to get comments for a GitHub issue. +func GetIssueComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_issue_comments", mcp.WithDescription(t("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION", "Get comments for a GitHub issue")), mcp.WithString("owner", diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index 485169fd..04a2ae19 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -18,7 +18,7 @@ import ( func Test_GetIssue(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getIssue(mockClient, translations.NullTranslationHelper) + tool, _ := GetIssue(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_issue", tool.Name) assert.NotEmpty(t, tool.Description) @@ -82,7 +82,7 @@ func Test_GetIssue(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getIssue(client, translations.NullTranslationHelper) + _, handler := GetIssue(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -114,7 +114,7 @@ func Test_GetIssue(t *testing.T) { func Test_AddIssueComment(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := addIssueComment(mockClient, translations.NullTranslationHelper) + tool, _ := AddIssueComment(mockClient, translations.NullTranslationHelper) assert.Equal(t, "add_issue_comment", tool.Name) assert.NotEmpty(t, tool.Description) @@ -185,7 +185,7 @@ func Test_AddIssueComment(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := addIssueComment(client, translations.NullTranslationHelper) + _, handler := AddIssueComment(client, translations.NullTranslationHelper) // Create call request request := mcp.CallToolRequest{ @@ -237,7 +237,7 @@ func Test_AddIssueComment(t *testing.T) { func Test_SearchIssues(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := searchIssues(mockClient, translations.NullTranslationHelper) + tool, _ := SearchIssues(mockClient, translations.NullTranslationHelper) assert.Equal(t, "search_issues", tool.Name) assert.NotEmpty(t, tool.Description) @@ -352,7 +352,7 @@ func Test_SearchIssues(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := searchIssues(client, translations.NullTranslationHelper) + _, handler := SearchIssues(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -393,7 +393,7 @@ func Test_SearchIssues(t *testing.T) { func Test_CreateIssue(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createIssue(mockClient, translations.NullTranslationHelper) + tool, _ := CreateIssue(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_issue", tool.Name) assert.NotEmpty(t, tool.Description) @@ -505,7 +505,7 @@ func Test_CreateIssue(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createIssue(client, translations.NullTranslationHelper) + _, handler := CreateIssue(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -566,7 +566,7 @@ func Test_CreateIssue(t *testing.T) { func Test_ListIssues(t *testing.T) { // Verify tool definition mockClient := github.NewClient(nil) - tool, _ := listIssues(mockClient, translations.NullTranslationHelper) + tool, _ := ListIssues(mockClient, translations.NullTranslationHelper) assert.Equal(t, "list_issues", tool.Name) assert.NotEmpty(t, tool.Description) @@ -697,7 +697,7 @@ func Test_ListIssues(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := listIssues(client, translations.NullTranslationHelper) + _, handler := ListIssues(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -742,7 +742,7 @@ func Test_ListIssues(t *testing.T) { func Test_UpdateIssue(t *testing.T) { // Verify tool definition mockClient := github.NewClient(nil) - tool, _ := updateIssue(mockClient, translations.NullTranslationHelper) + tool, _ := UpdateIssue(mockClient, translations.NullTranslationHelper) assert.Equal(t, "update_issue", tool.Name) assert.NotEmpty(t, tool.Description) @@ -881,7 +881,7 @@ func Test_UpdateIssue(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := updateIssue(client, translations.NullTranslationHelper) + _, handler := UpdateIssue(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -999,7 +999,7 @@ func Test_ParseISOTimestamp(t *testing.T) { func Test_GetIssueComments(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getIssueComments(mockClient, translations.NullTranslationHelper) + tool, _ := GetIssueComments(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_issue_comments", tool.Name) assert.NotEmpty(t, tool.Description) @@ -1099,7 +1099,7 @@ func Test_GetIssueComments(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getIssueComments(client, translations.NullTranslationHelper) + _, handler := GetIssueComments(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) diff --git a/pkg/github/server.go b/pkg/github/server.go index ec485a74..7ece3553 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -31,14 +31,14 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati s.AddResourceTemplate(getRepositoryResourcePrContent(client, t)) // Add GitHub tools - Issues - s.AddTool(getIssue(client, t)) - s.AddTool(searchIssues(client, t)) - s.AddTool(listIssues(client, t)) - s.AddTool(getIssueComments(client, t)) + s.AddTool(GetIssue(client, t)) + s.AddTool(SearchIssues(client, t)) + s.AddTool(ListIssues(client, t)) + s.AddTool(GetIssueComments(client, t)) if !readOnly { - s.AddTool(createIssue(client, t)) - s.AddTool(addIssueComment(client, t)) - s.AddTool(updateIssue(client, t)) + s.AddTool(CreateIssue(client, t)) + s.AddTool(AddIssueComment(client, t)) + s.AddTool(UpdateIssue(client, t)) } // Add GitHub tools - Pull Requests From e5986df456a8c010aecde6ed6e0627bae7e9cabb Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Mon, 7 Apr 2025 23:45:12 +0200 Subject: [PATCH 3/5] chore: export pr funcs --- pkg/github/pullrequests.go | 40 ++++++++++++++++----------------- pkg/github/pullrequests_test.go | 40 ++++++++++++++++----------------- pkg/github/server.go | 20 ++++++++--------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index 25090cb7..a5cd86b4 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -13,8 +13,8 @@ import ( "github.com/mark3labs/mcp-go/server" ) -// getPullRequest creates a tool to get details of a specific pull request. -func getPullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetPullRequest creates a tool to get details of a specific pull request. +func GetPullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_pull_request", mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_DESCRIPTION", "Get details of a specific pull request")), mcp.WithString("owner", @@ -67,8 +67,8 @@ func getPullRequest(client *github.Client, t translations.TranslationHelperFunc) } } -// listPullRequests creates a tool to list and filter repository pull requests. -func listPullRequests(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// ListPullRequests creates a tool to list and filter repository pull requests. +func ListPullRequests(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_pull_requests", mcp.WithDescription(t("TOOL_LIST_PULL_REQUESTS_DESCRIPTION", "List and filter repository pull requests")), mcp.WithString("owner", @@ -165,8 +165,8 @@ func listPullRequests(client *github.Client, t translations.TranslationHelperFun } } -// mergePullRequest creates a tool to merge a pull request. -func mergePullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// MergePullRequest creates a tool to merge a pull request. +func MergePullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("merge_pull_request", mcp.WithDescription(t("TOOL_MERGE_PULL_REQUEST_DESCRIPTION", "Merge a pull request")), mcp.WithString("owner", @@ -245,8 +245,8 @@ func mergePullRequest(client *github.Client, t translations.TranslationHelperFun } } -// getPullRequestFiles creates a tool to get the list of files changed in a pull request. -func getPullRequestFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetPullRequestFiles creates a tool to get the list of files changed in a pull request. +func GetPullRequestFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_pull_request_files", mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_FILES_DESCRIPTION", "Get the list of files changed in a pull request")), mcp.WithString("owner", @@ -300,8 +300,8 @@ func getPullRequestFiles(client *github.Client, t translations.TranslationHelper } } -// getPullRequestStatus creates a tool to get the combined status of all status checks for a pull request. -func getPullRequestStatus(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetPullRequestStatus creates a tool to get the combined status of all status checks for a pull request. +func GetPullRequestStatus(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_pull_request_status", mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_STATUS_DESCRIPTION", "Get the combined status of all status checks for a pull request")), mcp.WithString("owner", @@ -369,8 +369,8 @@ func getPullRequestStatus(client *github.Client, t translations.TranslationHelpe } } -// updatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch. -func updatePullRequestBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// UpdatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch. +func UpdatePullRequestBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("update_pull_request_branch", mcp.WithDescription(t("TOOL_UPDATE_PULL_REQUEST_BRANCH_DESCRIPTION", "Update a pull request branch with the latest changes from the base branch")), mcp.WithString("owner", @@ -439,8 +439,8 @@ func updatePullRequestBranch(client *github.Client, t translations.TranslationHe } } -// getPullRequestComments creates a tool to get the review comments on a pull request. -func getPullRequestComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetPullRequestComments creates a tool to get the review comments on a pull request. +func GetPullRequestComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_pull_request_comments", mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_COMMENTS_DESCRIPTION", "Get the review comments on a pull request")), mcp.WithString("owner", @@ -499,8 +499,8 @@ func getPullRequestComments(client *github.Client, t translations.TranslationHel } } -// getPullRequestReviews creates a tool to get the reviews on a pull request. -func getPullRequestReviews(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetPullRequestReviews creates a tool to get the reviews on a pull request. +func GetPullRequestReviews(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_pull_request_reviews", mcp.WithDescription(t("TOOL_GET_PULL_REQUEST_REVIEWS_DESCRIPTION", "Get the reviews on a pull request")), mcp.WithString("owner", @@ -553,8 +553,8 @@ func getPullRequestReviews(client *github.Client, t translations.TranslationHelp } } -// createPullRequestReview creates a tool to submit a review on a pull request. -func createPullRequestReview(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreatePullRequestReview creates a tool to submit a review on a pull request. +func CreatePullRequestReview(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_pull_request_review", mcp.WithDescription(t("TOOL_CREATE_PULL_REQUEST_REVIEW_DESCRIPTION", "Create a review on a pull request")), mcp.WithString("owner", @@ -745,8 +745,8 @@ func createPullRequestReview(client *github.Client, t translations.TranslationHe } } -// createPullRequest creates a tool to create a new pull request. -func createPullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreatePullRequest creates a tool to create a new pull request. +func CreatePullRequest(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_pull_request", mcp.WithDescription(t("TOOL_CREATE_PULL_REQUEST_DESCRIPTION", "Create a new pull request in a GitHub repository")), mcp.WithString("owner", diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go index cf1afcdc..34c41cc7 100644 --- a/pkg/github/pullrequests_test.go +++ b/pkg/github/pullrequests_test.go @@ -17,7 +17,7 @@ import ( func Test_GetPullRequest(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getPullRequest(mockClient, translations.NullTranslationHelper) + tool, _ := GetPullRequest(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_pull_request", tool.Name) assert.NotEmpty(t, tool.Description) @@ -94,7 +94,7 @@ func Test_GetPullRequest(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getPullRequest(client, translations.NullTranslationHelper) + _, handler := GetPullRequest(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -129,7 +129,7 @@ func Test_GetPullRequest(t *testing.T) { func Test_ListPullRequests(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := listPullRequests(mockClient, translations.NullTranslationHelper) + tool, _ := ListPullRequests(mockClient, translations.NullTranslationHelper) assert.Equal(t, "list_pull_requests", tool.Name) assert.NotEmpty(t, tool.Description) @@ -221,7 +221,7 @@ func Test_ListPullRequests(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := listPullRequests(client, translations.NullTranslationHelper) + _, handler := ListPullRequests(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -259,7 +259,7 @@ func Test_ListPullRequests(t *testing.T) { func Test_MergePullRequest(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := mergePullRequest(mockClient, translations.NullTranslationHelper) + tool, _ := MergePullRequest(mockClient, translations.NullTranslationHelper) assert.Equal(t, "merge_pull_request", tool.Name) assert.NotEmpty(t, tool.Description) @@ -336,7 +336,7 @@ func Test_MergePullRequest(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := mergePullRequest(client, translations.NullTranslationHelper) + _, handler := MergePullRequest(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -370,7 +370,7 @@ func Test_MergePullRequest(t *testing.T) { func Test_GetPullRequestFiles(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getPullRequestFiles(mockClient, translations.NullTranslationHelper) + tool, _ := GetPullRequestFiles(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_pull_request_files", tool.Name) assert.NotEmpty(t, tool.Description) @@ -448,7 +448,7 @@ func Test_GetPullRequestFiles(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getPullRequestFiles(client, translations.NullTranslationHelper) + _, handler := GetPullRequestFiles(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -486,7 +486,7 @@ func Test_GetPullRequestFiles(t *testing.T) { func Test_GetPullRequestStatus(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getPullRequestStatus(mockClient, translations.NullTranslationHelper) + tool, _ := GetPullRequestStatus(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_pull_request_status", tool.Name) assert.NotEmpty(t, tool.Description) @@ -608,7 +608,7 @@ func Test_GetPullRequestStatus(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getPullRequestStatus(client, translations.NullTranslationHelper) + _, handler := GetPullRequestStatus(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -647,7 +647,7 @@ func Test_GetPullRequestStatus(t *testing.T) { func Test_UpdatePullRequestBranch(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := updatePullRequestBranch(mockClient, translations.NullTranslationHelper) + tool, _ := UpdatePullRequestBranch(mockClient, translations.NullTranslationHelper) assert.Equal(t, "update_pull_request_branch", tool.Name) assert.NotEmpty(t, tool.Description) @@ -735,7 +735,7 @@ func Test_UpdatePullRequestBranch(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := updatePullRequestBranch(client, translations.NullTranslationHelper) + _, handler := UpdatePullRequestBranch(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -763,7 +763,7 @@ func Test_UpdatePullRequestBranch(t *testing.T) { func Test_GetPullRequestComments(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getPullRequestComments(mockClient, translations.NullTranslationHelper) + tool, _ := GetPullRequestComments(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_pull_request_comments", tool.Name) assert.NotEmpty(t, tool.Description) @@ -851,7 +851,7 @@ func Test_GetPullRequestComments(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getPullRequestComments(client, translations.NullTranslationHelper) + _, handler := GetPullRequestComments(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -890,7 +890,7 @@ func Test_GetPullRequestComments(t *testing.T) { func Test_GetPullRequestReviews(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getPullRequestReviews(mockClient, translations.NullTranslationHelper) + tool, _ := GetPullRequestReviews(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_pull_request_reviews", tool.Name) assert.NotEmpty(t, tool.Description) @@ -974,7 +974,7 @@ func Test_GetPullRequestReviews(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getPullRequestReviews(client, translations.NullTranslationHelper) + _, handler := GetPullRequestReviews(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -1013,7 +1013,7 @@ func Test_GetPullRequestReviews(t *testing.T) { func Test_CreatePullRequestReview(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createPullRequestReview(mockClient, translations.NullTranslationHelper) + tool, _ := CreatePullRequestReview(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_pull_request_review", tool.Name) assert.NotEmpty(t, tool.Description) @@ -1341,7 +1341,7 @@ func Test_CreatePullRequestReview(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createPullRequestReview(client, translations.NullTranslationHelper) + _, handler := CreatePullRequestReview(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -1384,7 +1384,7 @@ func Test_CreatePullRequestReview(t *testing.T) { func Test_CreatePullRequest(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createPullRequest(mockClient, translations.NullTranslationHelper) + tool, _ := CreatePullRequest(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_pull_request", tool.Name) assert.NotEmpty(t, tool.Description) @@ -1496,7 +1496,7 @@ func Test_CreatePullRequest(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createPullRequest(client, translations.NullTranslationHelper) + _, handler := CreatePullRequest(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) diff --git a/pkg/github/server.go b/pkg/github/server.go index 7ece3553..e5fdac2f 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -42,17 +42,17 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati } // Add GitHub tools - Pull Requests - s.AddTool(getPullRequest(client, t)) - s.AddTool(listPullRequests(client, t)) - s.AddTool(getPullRequestFiles(client, t)) - s.AddTool(getPullRequestStatus(client, t)) - s.AddTool(getPullRequestComments(client, t)) - s.AddTool(getPullRequestReviews(client, t)) + s.AddTool(GetPullRequest(client, t)) + s.AddTool(ListPullRequests(client, t)) + s.AddTool(GetPullRequestFiles(client, t)) + s.AddTool(GetPullRequestStatus(client, t)) + s.AddTool(GetPullRequestComments(client, t)) + s.AddTool(GetPullRequestReviews(client, t)) if !readOnly { - s.AddTool(mergePullRequest(client, t)) - s.AddTool(updatePullRequestBranch(client, t)) - s.AddTool(createPullRequestReview(client, t)) - s.AddTool(createPullRequest(client, t)) + s.AddTool(MergePullRequest(client, t)) + s.AddTool(UpdatePullRequestBranch(client, t)) + s.AddTool(CreatePullRequestReview(client, t)) + s.AddTool(CreatePullRequest(client, t)) } // Add GitHub tools - Repositories From 7ec593808c571b669d9a459aedf4e97641a0413f Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Tue, 8 Apr 2025 00:28:20 +0200 Subject: [PATCH 4/5] chore: export repository funcs --- pkg/github/repositories.go | 28 +++++++++++----------- pkg/github/repositories_test.go | 28 +++++++++++----------- pkg/github/repository_resource.go | 33 +++++++++++++------------- pkg/github/repository_resource_test.go | 22 ++++++++--------- pkg/github/server.go | 24 +++++++++---------- 5 files changed, 68 insertions(+), 67 deletions(-) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 5b8725d1..7725438b 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -13,8 +13,8 @@ import ( "github.com/mark3labs/mcp-go/server" ) -// listCommits creates a tool to get commits of a branch in a repository. -func listCommits(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// ListCommits creates a tool to get commits of a branch in a repository. +func ListCommits(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_commits", mcp.WithDescription(t("TOOL_LIST_COMMITS_DESCRIPTION", "Get list of commits of a branch in a GitHub repository")), mcp.WithString("owner", @@ -79,8 +79,8 @@ func listCommits(client *github.Client, t translations.TranslationHelperFunc) (t } } -// createOrUpdateFile creates a tool to create or update a file in a GitHub repository. -func createOrUpdateFile(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository. +func CreateOrUpdateFile(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_or_update_file", mcp.WithDescription(t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", "Create or update a single file in a GitHub repository")), mcp.WithString("owner", @@ -180,8 +180,8 @@ func createOrUpdateFile(client *github.Client, t translations.TranslationHelperF } } -// createRepository creates a tool to create a new GitHub repository. -func createRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreateRepository creates a tool to create a new GitHub repository. +func CreateRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_repository", mcp.WithDescription(t("TOOL_CREATE_REPOSITORY_DESCRIPTION", "Create a new GitHub repository in your account")), mcp.WithString("name", @@ -246,8 +246,8 @@ func createRepository(client *github.Client, t translations.TranslationHelperFun } } -// getFileContents creates a tool to get the contents of a file or directory from a GitHub repository. -func getFileContents(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetFileContents creates a tool to get the contents of a file or directory from a GitHub repository. +func GetFileContents(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_file_contents", mcp.WithDescription(t("TOOL_GET_FILE_CONTENTS_DESCRIPTION", "Get the contents of a file or directory from a GitHub repository")), mcp.WithString("owner", @@ -315,8 +315,8 @@ func getFileContents(client *github.Client, t translations.TranslationHelperFunc } } -// forkRepository creates a tool to fork a repository. -func forkRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// ForkRepository creates a tool to fork a repository. +func ForkRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("fork_repository", mcp.WithDescription(t("TOOL_FORK_REPOSITORY_DESCRIPTION", "Fork a GitHub repository to your account or specified organization")), mcp.WithString("owner", @@ -378,8 +378,8 @@ func forkRepository(client *github.Client, t translations.TranslationHelperFunc) } } -// createBranch creates a tool to create a new branch. -func createBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// CreateBranch creates a tool to create a new branch. +func CreateBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("create_branch", mcp.WithDescription(t("TOOL_CREATE_BRANCH_DESCRIPTION", "Create a new branch in a GitHub repository")), mcp.WithString("owner", @@ -458,8 +458,8 @@ func createBranch(client *github.Client, t translations.TranslationHelperFunc) ( } } -// pushFiles creates a tool to push multiple files in a single commit to a GitHub repository. -func pushFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// PushFiles creates a tool to push multiple files in a single commit to a GitHub repository. +func PushFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("push_files", mcp.WithDescription(t("TOOL_PUSH_FILES_DESCRIPTION", "Push multiple files to a GitHub repository in a single commit")), mcp.WithString("owner", diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index f7ed8e71..5c47183d 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -18,7 +18,7 @@ import ( func Test_GetFileContents(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := getFileContents(mockClient, translations.NullTranslationHelper) + tool, _ := GetFileContents(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_file_contents", tool.Name) assert.NotEmpty(t, tool.Description) @@ -132,7 +132,7 @@ func Test_GetFileContents(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getFileContents(client, translations.NullTranslationHelper) + _, handler := GetFileContents(client, translations.NullTranslationHelper) // Create call request request := mcp.CallToolRequest{ @@ -189,7 +189,7 @@ func Test_GetFileContents(t *testing.T) { func Test_ForkRepository(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := forkRepository(mockClient, translations.NullTranslationHelper) + tool, _ := ForkRepository(mockClient, translations.NullTranslationHelper) assert.Equal(t, "fork_repository", tool.Name) assert.NotEmpty(t, tool.Description) @@ -259,7 +259,7 @@ func Test_ForkRepository(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := forkRepository(client, translations.NullTranslationHelper) + _, handler := ForkRepository(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -287,7 +287,7 @@ func Test_ForkRepository(t *testing.T) { func Test_CreateBranch(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createBranch(mockClient, translations.NullTranslationHelper) + tool, _ := CreateBranch(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_branch", tool.Name) assert.NotEmpty(t, tool.Description) @@ -445,7 +445,7 @@ func Test_CreateBranch(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createBranch(client, translations.NullTranslationHelper) + _, handler := CreateBranch(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -478,7 +478,7 @@ func Test_CreateBranch(t *testing.T) { func Test_ListCommits(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := listCommits(mockClient, translations.NullTranslationHelper) + tool, _ := ListCommits(mockClient, translations.NullTranslationHelper) assert.Equal(t, "list_commits", tool.Name) assert.NotEmpty(t, tool.Description) @@ -614,7 +614,7 @@ func Test_ListCommits(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := listCommits(client, translations.NullTranslationHelper) + _, handler := ListCommits(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -652,7 +652,7 @@ func Test_ListCommits(t *testing.T) { func Test_CreateOrUpdateFile(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createOrUpdateFile(mockClient, translations.NullTranslationHelper) + tool, _ := CreateOrUpdateFile(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_or_update_file", tool.Name) assert.NotEmpty(t, tool.Description) @@ -775,7 +775,7 @@ func Test_CreateOrUpdateFile(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createOrUpdateFile(client, translations.NullTranslationHelper) + _, handler := CreateOrUpdateFile(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -815,7 +815,7 @@ func Test_CreateOrUpdateFile(t *testing.T) { func Test_CreateRepository(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := createRepository(mockClient, translations.NullTranslationHelper) + tool, _ := CreateRepository(mockClient, translations.NullTranslationHelper) assert.Equal(t, "create_repository", tool.Name) assert.NotEmpty(t, tool.Description) @@ -923,7 +923,7 @@ func Test_CreateRepository(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := createRepository(client, translations.NullTranslationHelper) + _, handler := CreateRepository(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -961,7 +961,7 @@ func Test_CreateRepository(t *testing.T) { func Test_PushFiles(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := pushFiles(mockClient, translations.NullTranslationHelper) + tool, _ := PushFiles(mockClient, translations.NullTranslationHelper) assert.Equal(t, "push_files", tool.Name) assert.NotEmpty(t, tool.Description) @@ -1256,7 +1256,7 @@ func Test_PushFiles(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := pushFiles(client, translations.NullTranslationHelper) + _, handler := PushFiles(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) diff --git a/pkg/github/repository_resource.go b/pkg/github/repository_resource.go index 8b2ba7a7..47cb8bf6 100644 --- a/pkg/github/repository_resource.go +++ b/pkg/github/repository_resource.go @@ -17,52 +17,53 @@ import ( "github.com/mark3labs/mcp-go/server" ) -// getRepositoryResourceContent defines the resource template and handler for getting repository content. -func getRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { +// GetRepositoryResourceContent defines the resource template and handler for getting repository content. +func GetRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( "repo://{owner}/{repo}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_DESCRIPTION", "Repository Content"), ), - repositoryResourceContentsHandler(client) + RepositoryResourceContentsHandler(client) } -// getRepositoryContent defines the resource template and handler for getting repository content for a branch. -func getRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { +// GetRepositoryResourceBranchContent defines the resource template and handler for getting repository content for a branch. +func GetRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION", "Repository Content for specific branch"), ), - repositoryResourceContentsHandler(client) + RepositoryResourceContentsHandler(client) } -// getRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit. -func getRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { +// GetRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit. +func GetRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION", "Repository Content for specific commit"), ), - repositoryResourceContentsHandler(client) + RepositoryResourceContentsHandler(client) } -// getRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag. -func getRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { +// GetRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag. +func GetRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION", "Repository Content for specific tag"), ), - repositoryResourceContentsHandler(client) + RepositoryResourceContentsHandler(client) } -// getRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request. -func getRepositoryResourcePrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { +// GetRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request. +func GetRepositoryResourcePrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) { return mcp.NewResourceTemplate( "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", // Resource template t("RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION", "Repository Content for specific pull request"), ), - repositoryResourceContentsHandler(client) + RepositoryResourceContentsHandler(client) } -func repositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) { +// RepositoryResourceContentsHandler returns a handler function for repository content requests. +func RepositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) { return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) { // the matcher will give []string with one element // https://github.com/mark3labs/mcp-go/pull/54 diff --git a/pkg/github/repository_resource_test.go b/pkg/github/repository_resource_test.go index adad8744..c274d1b5 100644 --- a/pkg/github/repository_resource_test.go +++ b/pkg/github/repository_resource_test.go @@ -234,7 +234,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { client := github.NewClient(tc.mockedClient) - handler := repositoryResourceContentsHandler(client) + handler := RepositoryResourceContentsHandler(client) request := mcp.ReadResourceRequest{ Params: struct { @@ -258,26 +258,26 @@ func Test_repositoryResourceContentsHandler(t *testing.T) { } } -func Test_getRepositoryResourceContent(t *testing.T) { - tmpl, _ := getRepositoryResourceContent(nil, translations.NullTranslationHelper) +func Test_GetRepositoryResourceContent(t *testing.T) { + tmpl, _ := GetRepositoryResourceContent(nil, translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/contents{/path*}", tmpl.URITemplate.Raw()) } -func Test_getRepositoryResourceBranchContent(t *testing.T) { - tmpl, _ := getRepositoryResourceBranchContent(nil, translations.NullTranslationHelper) +func Test_GetRepositoryResourceBranchContent(t *testing.T) { + tmpl, _ := GetRepositoryResourceBranchContent(nil, translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", tmpl.URITemplate.Raw()) } -func Test_getRepositoryResourceCommitContent(t *testing.T) { - tmpl, _ := getRepositoryResourceCommitContent(nil, translations.NullTranslationHelper) +func Test_GetRepositoryResourceCommitContent(t *testing.T) { + tmpl, _ := GetRepositoryResourceCommitContent(nil, translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", tmpl.URITemplate.Raw()) } -func Test_getRepositoryResourceTagContent(t *testing.T) { - tmpl, _ := getRepositoryResourceTagContent(nil, translations.NullTranslationHelper) +func Test_GetRepositoryResourceTagContent(t *testing.T) { + tmpl, _ := GetRepositoryResourceTagContent(nil, translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", tmpl.URITemplate.Raw()) } -func Test_getRepositoryResourcePrContent(t *testing.T) { - tmpl, _ := getRepositoryResourcePrContent(nil, translations.NullTranslationHelper) +func Test_GetRepositoryResourcePrContent(t *testing.T) { + tmpl, _ := GetRepositoryResourcePrContent(nil, translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", tmpl.URITemplate.Raw()) } diff --git a/pkg/github/server.go b/pkg/github/server.go index e5fdac2f..352d9697 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -24,11 +24,11 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati server.WithLogging()) // Add GitHub Resources - s.AddResourceTemplate(getRepositoryResourceContent(client, t)) - s.AddResourceTemplate(getRepositoryResourceBranchContent(client, t)) - s.AddResourceTemplate(getRepositoryResourceCommitContent(client, t)) - s.AddResourceTemplate(getRepositoryResourceTagContent(client, t)) - s.AddResourceTemplate(getRepositoryResourcePrContent(client, t)) + s.AddResourceTemplate(GetRepositoryResourceContent(client, t)) + s.AddResourceTemplate(GetRepositoryResourceBranchContent(client, t)) + s.AddResourceTemplate(GetRepositoryResourceCommitContent(client, t)) + s.AddResourceTemplate(GetRepositoryResourceTagContent(client, t)) + s.AddResourceTemplate(GetRepositoryResourcePrContent(client, t)) // Add GitHub tools - Issues s.AddTool(GetIssue(client, t)) @@ -57,14 +57,14 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati // Add GitHub tools - Repositories s.AddTool(searchRepositories(client, t)) - s.AddTool(getFileContents(client, t)) - s.AddTool(listCommits(client, t)) + s.AddTool(GetFileContents(client, t)) + s.AddTool(ListCommits(client, t)) if !readOnly { - s.AddTool(createOrUpdateFile(client, t)) - s.AddTool(createRepository(client, t)) - s.AddTool(forkRepository(client, t)) - s.AddTool(createBranch(client, t)) - s.AddTool(pushFiles(client, t)) + s.AddTool(CreateOrUpdateFile(client, t)) + s.AddTool(CreateRepository(client, t)) + s.AddTool(ForkRepository(client, t)) + s.AddTool(CreateBranch(client, t)) + s.AddTool(PushFiles(client, t)) } // Add GitHub tools - Search From 86700d1b4e01f9e535f2f27af57d15be171f3786 Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Tue, 8 Apr 2025 00:32:14 +0200 Subject: [PATCH 5/5] chore: export search funcs --- pkg/github/search.go | 12 ++++++------ pkg/github/search_test.go | 12 ++++++------ pkg/github/server.go | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/github/search.go b/pkg/github/search.go index 117e8298..46fed599 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -12,8 +12,8 @@ import ( "github.com/mark3labs/mcp-go/server" ) -// searchRepositories creates a tool to search for GitHub repositories. -func searchRepositories(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// SearchRepositories creates a tool to search for GitHub repositories. +func SearchRepositories(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("search_repositories", mcp.WithDescription(t("TOOL_SEARCH_REPOSITORIES_DESCRIPTION", "Search for GitHub repositories")), mcp.WithString("query", @@ -62,8 +62,8 @@ func searchRepositories(client *github.Client, t translations.TranslationHelperF } } -// searchCode creates a tool to search for code across GitHub repositories. -func searchCode(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// SearchCode creates a tool to search for code across GitHub repositories. +func SearchCode(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("search_code", mcp.WithDescription(t("TOOL_SEARCH_CODE_DESCRIPTION", "Search for code across GitHub repositories")), mcp.WithString("q", @@ -129,8 +129,8 @@ func searchCode(client *github.Client, t translations.TranslationHelperFunc) (to } } -// searchUsers creates a tool to search for GitHub users. -func searchUsers(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// SearchUsers creates a tool to search for GitHub users. +func SearchUsers(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("search_users", mcp.WithDescription(t("TOOL_SEARCH_USERS_DESCRIPTION", "Search for GitHub users")), mcp.WithString("q", diff --git a/pkg/github/search_test.go b/pkg/github/search_test.go index bf1bff45..b000a0bf 100644 --- a/pkg/github/search_test.go +++ b/pkg/github/search_test.go @@ -16,7 +16,7 @@ import ( func Test_SearchRepositories(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := searchRepositories(mockClient, translations.NullTranslationHelper) + tool, _ := SearchRepositories(mockClient, translations.NullTranslationHelper) assert.Equal(t, "search_repositories", tool.Name) assert.NotEmpty(t, tool.Description) @@ -122,7 +122,7 @@ func Test_SearchRepositories(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := searchRepositories(client, translations.NullTranslationHelper) + _, handler := SearchRepositories(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -163,7 +163,7 @@ func Test_SearchRepositories(t *testing.T) { func Test_SearchCode(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := searchCode(mockClient, translations.NullTranslationHelper) + tool, _ := SearchCode(mockClient, translations.NullTranslationHelper) assert.Equal(t, "search_code", tool.Name) assert.NotEmpty(t, tool.Description) @@ -273,7 +273,7 @@ func Test_SearchCode(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := searchCode(client, translations.NullTranslationHelper) + _, handler := SearchCode(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -314,7 +314,7 @@ func Test_SearchCode(t *testing.T) { func Test_SearchUsers(t *testing.T) { // Verify tool definition once mockClient := github.NewClient(nil) - tool, _ := searchUsers(mockClient, translations.NullTranslationHelper) + tool, _ := SearchUsers(mockClient, translations.NullTranslationHelper) assert.Equal(t, "search_users", tool.Name) assert.NotEmpty(t, tool.Description) @@ -428,7 +428,7 @@ func Test_SearchUsers(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := searchUsers(client, translations.NullTranslationHelper) + _, handler := SearchUsers(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) diff --git a/pkg/github/server.go b/pkg/github/server.go index 352d9697..d8a9b230 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -56,7 +56,7 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati } // Add GitHub tools - Repositories - s.AddTool(searchRepositories(client, t)) + s.AddTool(SearchRepositories(client, t)) s.AddTool(GetFileContents(client, t)) s.AddTool(ListCommits(client, t)) if !readOnly { @@ -68,8 +68,8 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati } // Add GitHub tools - Search - s.AddTool(searchCode(client, t)) - s.AddTool(searchUsers(client, t)) + s.AddTool(SearchCode(client, t)) + s.AddTool(SearchUsers(client, t)) // Add GitHub tools - Users s.AddTool(getMe(client, t))