8000 chore: export repository funcs · github/github-mcp-server@c1bdd6a · GitHub
[go: up one dir, main page]

Skip to content

Commit c1bdd6a

Browse files
chore: export repository funcs
1 parent c85dd07 commit c1bdd6a

File tree

5 files changed

+68
-67
lines changed

5 files changed

+68
-67
lines changed

pkg/github/repositories.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"github.com/mark3labs/mcp-go/server"
1414
)
1515

16-
// listCommits creates a tool to get commits of a branch in a repository.
17-
func listCommits(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
// ListCommits creates a tool to get commits of a branch in a repository.
17+
func ListCommits(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1818
return mcp.NewTool("list_commits",
1919
mcp.WithDescription(t("TOOL_LIST_COMMITS_DESCRIPTION", "Get list of commits of a branch in a GitHub repository")),
2020
mcp.WithString("owner",
@@ -79,8 +79,8 @@ func listCommits(client *github.Client, t translations.TranslationHelperFunc) (t
7979
}
8080
}
8181

82-
// createOrUpdateFile creates a tool to create or update a file in a GitHub repository.
83-
func createOrUpdateFile(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
82+
// CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository.
83+
func CreateOrUpdateFile(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
8484
return mcp.NewTool("create_or_update_file",
8585
mcp.WithDescription(t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", "Create or update a single file in a GitHub repository")),
8686
mcp.WithString("owner",
@@ -180,8 +180,8 @@ func createOrUpdateFile(client *github.Client, t translations.TranslationHelperF
180180
}
181181
}
182182

183-
// createRepository creates a tool to create a new GitHub repository.
184-
func createRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
183+
// CreateRepository creates a tool to create a new GitHub repository.
184+
func CreateRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
185185
return mcp.NewTool("create_repository",
186186
mcp.WithDescription(t("TOOL_CREATE_REPOSITORY_DESCRIPTION", "Create a new GitHub repository in your account")),
187187
mcp.WithString("name",
@@ -246,8 +246,8 @@ func createRepository(client *github.Client, t translations.TranslationHelperFun
246246
}
247247
}
248248

249-
// getFileContents creates a tool to get the contents of a file or directory from a GitHub repository.
250-
func getFileContents(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
249+
// GetFileContents creates a tool to get the contents of a file or directory from a GitHub repository.
250+
func GetFileContents(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
251251
return mcp.NewTool("get_file_contents",
252252
mcp.WithDescription(t("TOOL_GET_FILE_CONTENTS_DESCRIPTION", "Get the contents of a file or directory from a GitHub repository")),
253253
mcp.WithString("owner",
@@ -315,8 +315,8 @@ func getFileContents(client *github.Client, t translations.TranslationHelperFunc
315315
}
316316
}
317317

318-
// forkRepository creates a tool to fork a repository.
319-
func forkRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
318+
// ForkRepository creates a tool to fork a repository.
319+
func ForkRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
320320
return mcp.NewTool("fork_repository",
321321
mcp.WithDescription(t("TOOL_FORK_REPOSITORY_DESCRIPTION", "Fork a GitHub repository to your account or specified organization")),
322322
mcp.WithString("owner",
@@ -378,8 +378,8 @@ func forkRepository(client *github.Client, t translations.TranslationHelperFunc)
378378
}
379379
}
380380

381-
// createBranch creates a tool to create a new branch.
382-
func createBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
381+
// CreateBranch creates a tool to create a new branch.
382+
func CreateBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
383383
return mcp.NewTool("create_branch",
384384
mcp.WithDescription(t("TOOL_CREATE_BRANCH_DESCRIPTION", "Create a new branch in a GitHub repository")),
385385
mcp.WithString("owner",
@@ -458,8 +458,8 @@ func createBranch(client *github.Client, t translations.TranslationHelperFunc) (
458458
}
459459
}
460460

461-
// pushFiles creates a tool to push multiple files in a single commit to a GitHub repository.
462-
func pushFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
461+
// PushFiles creates a tool to push multiple files in a single commit to a GitHub repository.
462+
func PushFiles(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
463463
return mcp.NewTool("push_files",
464464
mcp.WithDescription(t("TOOL_PUSH_FILES_DESCRIPTION", "Push multiple files to a GitHub repository in a single commit")),
465465
mcp.WithString("owner",

pkg/github/repositories_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func Test_GetFileContents(t *testing.T) {
1919
// Verify tool definition once
2020
mockClient := github.NewClient(nil)
21-
tool, _ := getFileContents(mockClient, translations.NullTranslationHelper)
21+
tool, _ := GetFileContents(mockClient, translations.NullTranslationHelper)
2222

2323
assert.Equal(t, "get_file_contents", tool.Name)
2424
assert.NotEmpty(t, tool.Description)
@@ -132,7 +132,7 @@ func Test_GetFileContents(t *testing.T) {
132132
t.Run(tc.name, func(t *testing.T) {
133133
// Setup client with mock
134134
client := github.NewClient(tc.mockedClient)
135-
_, handler := getFileContents(client, translations.NullTranslationHelper)
135+
_, handler := GetFileContents(client, translations.NullTranslationHelper)
136136

137137
// Create call request
138138
request := mcp.CallToolRequest{
@@ -189,7 +189,7 @@ func Test_GetFileContents(t *testing.T) {
189189
func Test_ForkRepository(t *testing.T) {
190190
// Verify tool definition once
191191
mockClient := github.NewClient(nil)
192-
tool, _ := forkRepository(mockClient, translations.NullTranslationHelper)
192+
tool, _ := ForkRepository(mockClient, translations.NullTranslationHelper)
193193

194194
assert.Equal(t, "fork_repository", tool.Name)
195195
assert.NotEmpty(t, tool.Description)
@@ -259,7 +259,7 @@ func Test_ForkRepository(t *testing.T) {
259259
t.Run(tc.name, func(t *testing.T) {
260260
// Setup client with mock
261261
client := github.NewClient(tc.mockedClient)
262-
_, handler := forkRepository(client, translations.NullTranslationHelper)
262+
_, handler := ForkRepository(client, translations.NullTranslationHelper)
263263

264264
// Create call request
265265
request := createMCPRequest(tc.requestArgs)
@@ -287,7 +287,7 @@ func Test_ForkRepository(t *testing.T) {
287287
func Test_CreateBranch(t *testing.T) {
288288
// Verify tool definition once
289289
mockClient := github.NewClient(nil)
290-
tool, _ := createBranch(mockClient, translations.NullTranslationHelper)
290+
tool, _ := CreateBranch(mockClient, translations.NullTranslationHelper)
291291

292292
assert.Equal(t, "create_branch", tool.Name)
293293
assert.NotEmpty(t, tool.Description)
@@ -445,7 +445,7 @@ func Test_CreateBranch(t *testing.T) {
445445
t.Run(tc.name, func(t *testing.T) {
446446
// Setup client with mock
447447
client := github.NewClient(tc.mockedClient)
448-
_, handler := createBranch(client, translations.NullTranslationHelper)
448+
_, handler := CreateBranch(client, translations.NullTranslationHelper)
449449

450450
// Create call request
451451
request := createMCPRequest(tc.requestArgs)
@@ -478,7 +478,7 @@ func Test_CreateBranch(t *testing.T) {
478478
func Test_ListCommits(t *testing.T) {
479479
// Verify tool definition once
480480
mockClient := github.NewClient(nil)
481-
tool, _ := listCommits(mockClient, translations.NullTranslationHelper)
481+
tool, _ := ListCommits(mockClient, translations.NullTranslationHelper)
482482

483483
assert.Equal(t, "list_commits", tool.Name)
484484
assert.NotEmpty(t, tool.Description)
@@ -614,7 +614,7 @@ func Test_ListCommits(t *testing.T) {
614614
t.Run(tc.name, func(t *testing.T) {
615615
// Setup client with mock
616616
client := github.NewClient(tc.mockedClient)
617-
_, handler := listCommits(client, translations.NullTranslationH F42D elper)
617+
_, handler := ListCommits(client, translations.NullTranslationHelper)
618618

619619
// Create call request
620620
request := createMCPRequest(tc.requestArgs)
@@ -652,7 +652,7 @@ func Test_ListCommits(t *testing.T) {
652652
func Test_CreateOrUpdateFile(t *testing.T) {
653653
// Verify tool definition once
654654
mockClient := github.NewClient(nil)
655-
tool, _ := createOrUpdateFile(mockClient, translations.NullTranslationHelper)
655+
tool, _ := CreateOrUpdateFile(mockClient, translations.NullTranslationHelper)
656656

657657
assert.Equal(t, "create_or_update_file", tool.Name)
658658
assert.NotEmpty(t, tool.Description)
@@ -775,7 +775,7 @@ func Test_CreateOrUpdateFile(t *testing.T) {
775775
t.Run(tc.name, func(t *testing.T) {
776776
// Setup client with mock
777777
client := github.NewClient(tc.mockedClient)
778-
_, handler := createOrUpdateFile(client, translations.NullTranslationHelper)
778+
_, handler := CreateOrUpdateFile(client, translations.NullTranslationHelper)
779779

780780
// Create call request
781781
request := createMCPRequest(tc.requestArgs)
@@ -815,7 +815,7 @@ func Test_CreateOrUpdateFile(t *testing.T) {
815815
func Test_CreateRepository(t *testing.T) {
816816
// Verify tool definition once
817817
mockClient := github.NewClient(nil)
818-
tool, _ := createRepository(mockClient, translations.NullTranslationHelper)
818+
tool, _ := CreateRepository(mockClient, translations.NullTranslationHelper)
819819

820820
assert.Equal(t, "create_repository", tool.Name)
821821
assert.NotEmpty(t, tool.Description)
@@ -923,7 +923,7 @@ func Test_CreateRepository(t *testing.T) {
923923
t.Run(tc.name, func(t *testing.T) {
924924
// Setup client with mock
925925
client := github.NewClient(tc.mockedClient)
926-
_, handler := createRepository(client, translations.NullTranslationHelper)
926+
_, handler := CreateRepository(client, translations.NullTranslationHelper)
927927

928928
// Create call request
929929
request := createMCPRequest(tc.requestArgs)
@@ -961,7 +961,7 @@ func Test_CreateRepository(t *testing.T) {
961961
func Test_PushFiles(t *testing.T) {
962962
// Verify tool definition once
963 F438 963
mockClient := github.NewClient(nil)
964-
tool, _ := pushFiles(mockClient, translations.NullTranslationHelper)
964+
tool, _ := PushFiles(mockClient, translations.NullTranslationHelper)
965965

966966
assert.Equal(t, "push_files", tool.Name)
967967
assert.NotEmpty(t, tool.Description)
@@ -1256,7 +1256,7 @@ func Test_PushFiles(t *testing.T) {
12561256
t.Run(tc.name, func(t *testing.T) {
12571257
// Setup client with mock
12581258
client := github.NewClient(tc.mockedClient)
1259-
_, handler := pushFiles(client, translations.NullTranslationHelper)
1259+
_, handler := PushFiles(client, translations.NullTranslationHelper)
12601260

12611261
// Create call request
12621262
request := createMCPRequest(tc.requestArgs)

pkg/github/repository_resource.go

Lines changed: 17 additions & 16 deletions
< 10000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,53 @@ import (
1717
"github.com/mark3labs/mcp-go/server"
1818
)
1919

20-
// getRepositoryResourceContent defines the resource template and handler for getting repository content.
21-
func getRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
20+
// GetRepositoryResourceContent defines the resource template and handler for getting repository content.
21+
func GetRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
2222
return mcp.NewResourceTemplate(
2323
"repo://{owner}/{repo}/contents{/path*}", // Resource template
2424
t("RESOURCE_REPOSITORY_CONTENT_DESCRIPTION", "Repository Content"),
2525
),
26-
repositoryResourceContentsHandler(client)
26+
RepositoryResourceContentsHandler(client)
2727
}
2828

29-
// getRepositoryContent defines the resource template and handler for getting repository content for a branch.
30-
func getRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
29+
// GetRepositoryResourceBranchContent defines the resource template and handler for getting repository content for a branch.
30+
func GetRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
3131
return mcp.NewResourceTemplate(
3232
"repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource template
3333
t("RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION", "Repository Content for specific branch"),
3434
),
35-
repositoryResourceContentsHandler(client)
35+
RepositoryResourceContentsHandler(client)
3636
}
3737

38-
// getRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit.
39-
func getRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
38+
// GetRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit.
39+
func GetRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
4040
return mcp.NewResourceTemplate(
4141
"repo://{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource template
4242
t("RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION", "Repository Content for specific commit"),
4343
),
44-
repositoryResourceContentsHandler(client)
44+
RepositoryResourceContentsHandler(client)
4545
}
4646

47-
// getRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag.
48-
func getRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
47+
// GetRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag.
48+
func GetRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
4949
return mcp.NewResourceTemplate(
5050
"repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource template
5151
t("RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION", "Repository Content for specific tag"),
5252
),
53-
repositoryResourceContentsHandler(client)
53+
RepositoryResourceContentsHandler(client)
5454
}
5555

56-
// getRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request.
57-
func getRepositoryResourcePrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
56+
// GetRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request.
57+
func GetRepositoryResourcePrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
5858
return mcp.NewResourceTemplate(
5959
"repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", // Resource template
6060
t("RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION", "Repository Content for specific pull request"),
6161
),
62-
repositoryResourceContentsHandler(client)
62+
RepositoryResourceContentsHandler(client)
6363
}
6464

65-
func repositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
65+
// RepositoryResourceContentsHandler returns a handler function for repository content requests.
66+
func RepositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
6667
return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
6768
// the matcher will give []string with one element
6869
// https://github.com/mark3labs/mcp-go/pull/54

pkg/github/repository_resource_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
234234
for _, tc := range tests {
235235
t.Run(tc.name, func(t *testing.T) {
236236
client := github.NewClient(tc.mockedClient)
237-
handler := repositoryResourceContentsHandler(client)
237+
handler := RepositoryResourceContentsHandler(client)
238238

239239
request := mcp.ReadResourceRequest{
240240
Params: struct {
@@ -258,26 +258,26 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
258258
}
259259
}
260260

261-
func Test_getRepositoryResourceContent(t *testing.T) {
262-
tmpl, _ := getRepositoryResourceContent(nil, translations.NullTranslationHelper)
261+
func Test_GetRepositoryResourceContent(t *testing.T) {
262+
tmpl, _ := GetRepositoryResourceContent(nil, translations.NullTranslationHelper)
263263
require.Equal(t, "repo://{owner}/{repo}/contents{/path*}", tmpl.URITemplate.Raw())
264264
}
265265

266-
func Test_getRepositoryResourceBranchContent(t *testing.T) {
267-
tmpl, _ := getRepositoryResourceBranchContent(nil, translations.NullTranslationHelper)
266+
func Test_GetRepositoryResourceBranchContent(t *testing.T) {
267+
tmpl, _ := GetRepositoryResourceBranchContent(nil, translations.NullTranslationHelper)
268268
require.Equal(t, "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", tmpl.URITemplate.Raw())
269269
}
270-
func Test_getRepositoryResourceCommitContent(t *testing.T) {
271-
tmpl, _ := getRepositoryResourceCommitContent(nil, translations.NullTranslationHelper)
270+
func Test_GetRepositoryResourceCommitContent(t *testing.T) {
271+
tmpl, _ := GetRepositoryResourceCommitContent(nil, translations.NullTranslationHelper)
272272
require.Equal(t, "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", tmpl.URITemplate.Raw())
273273
}
274274

275-
func Test_getRepositoryResourceTagContent(t *testing.T) {
276-
tmpl, _ := getRepositoryResourceTagContent(nil, translations.NullTranslationHelper)
275+
func Test_GetRepositoryResourceTagContent(t *testing.T) {
276+
tmpl, _ := GetRepositoryResourceTagContent(nil, translations.NullTranslationHelper)
277277
require.Equal(t, "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", tmpl.URITemplate.Raw())
278278
}
279279

280-
func Test_getRepositoryResourcePrContent(t *testing.T) {
281-
tmpl, _ := getRepositoryResourcePrContent(nil, translations.NullTranslationHelper)
280+
func Test_GetRepositoryResourcePrContent(t *testing.T) {
281+
tmpl, _ := GetRepositoryResourcePrContent(nil, translations.NullTranslationHelper)
282282
require.Equal(t, "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", tmpl.URITemplate.Raw())
283283
}

pkg/github/server.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati
2424
server.WithLogging())
2525

2626
// Add GitHub Resources
27-
s.AddResourceTemplate(getRepositoryResourceContent(client, t))
28-
s.AddResourceTemplate(getRepositoryResourceBranchContent(client, t))
29-
s.AddResourceTemplate(getRepositoryResourceCommitContent(client, t))
30-
s.AddResourceTemplate(getRepositoryResourceTagContent(client, t))
31-
s.AddResourceTemplate(getRepositoryResourcePrContent(client, t))
27+
s.AddResourceTemplate(GetRepositoryResourceContent(client, t))
28+
s.AddResourceTemplate(GetRepositoryResourceBranchContent(client, t))
29+
s.AddResourceTemplate(GetRepositoryResourceCommitContent(client, t))
30+
s.AddResourceTemplate(GetRepositoryResourceTagContent(client, t))
31+
s.AddResourceTemplate(GetRepositoryResourcePrContent(client, t))
3232

3333
// Add GitHub tools - Issues
3434
s.AddTool(GetIssue(client, t))
@@ -57,14 +57,14 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati
5757

5858
// Add GitHub tools - Repositories
5959
s.AddTool(searchRepositories(client, t))
60-
s.AddTool(getFileContents(client, t))
61-
s.AddTool(listCommits(client, t))
60+
s.AddTool(GetFileContents(client, t))
61+
s.AddTool(ListCommits(client, t))
6262
if !readOnly {
63-
s.AddTool(createOrUpdateFile(client, t))
64-
s.AddTool(createRepository(client, t))
65-
s.AddTool(forkRepository(client, t))
66-
s.AddTool(createBranch(client, t))
67-
s.AddTool(pushFiles(client, t))
63+
s.AddTool(CreateOrUpdateFile(client, t))
64+
s.AddTool(CreateRepository(client, t))
65+
s.AddTool(ForkRepository(client, t))
66+
s.AddTool(CreateBranch(client, t))
67+
s.AddTool(PushFiles(client, t))
6868
}
6969

7070
// Add GitHub tools - Search

0 commit comments

Comments
 (0)
0