Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: export repository funcs#166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SamMorrowDrums merged 1 commit intomainfromexport-repositories
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletionspkg/github/repositories.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,8 @@ import (
"github.com/mark3labs/mcp-go/server"
)

//listCommits creates a tool to get commits of a branch in a repository.
funclistCommits(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.
funcListCommits(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",
Expand DownExpand Up@@ -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.
funccreateOrUpdateFile(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.
funcCreateOrUpdateFile(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",
Expand DownExpand Up@@ -180,8 +180,8 @@ func createOrUpdateFile(client *github.Client, t translations.TranslationHelperF
}
}

//createRepository creates a tool to create a new GitHub repository.
funccreateRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
//CreateRepository creates a tool to create a new GitHub repository.
funcCreateRepository(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",
Expand DownExpand Up@@ -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.
funcgetFileContents(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.
funcGetFileContents(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",
Expand DownExpand Up@@ -315,8 +315,8 @@ func getFileContents(client *github.Client, t translations.TranslationHelperFunc
}
}

//forkRepository creates a tool to fork a repository.
funcforkRepository(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
//ForkRepository creates a tool to fork a repository.
funcForkRepository(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",
Expand DownExpand Up@@ -378,8 +378,8 @@ func forkRepository(client *github.Client, t translations.TranslationHelperFunc)
}
}

//createBranch creates a tool to create a new branch.
funccreateBranch(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
//CreateBranch creates a tool to create a new branch.
funcCreateBranch(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",
Expand DownExpand Up@@ -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.
funcpushFiles(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.
funcPushFiles(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",
Expand Down
28 changes: 14 additions & 14 deletionspkg/github/repositories_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand DownExpand Up@@ -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{
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand Down
33 changes: 17 additions & 16 deletionspkg/github/repository_resource.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,52 +17,53 @@ import (
"github.com/mark3labs/mcp-go/server"
)

//getRepositoryResourceContent defines the resource template and handler for getting repository content.
funcgetRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
//GetRepositoryResourceContent defines the resource template and handler for getting repository content.
funcGetRepositoryResourceContent(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.
funcgetRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
//GetRepositoryResourceBranchContent defines the resource template and handler for getting repository content for a branch.
funcGetRepositoryResourceBranchContent(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.
funcgetRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
//GetRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit.
funcGetRepositoryResourceCommitContent(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.
funcgetRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
//GetRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag.
funcGetRepositoryResourceTagContent(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.
funcgetRepositoryResourcePrContent(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.
funcGetRepositoryResourcePrContent(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
Expand Down
22 changes: 11 additions & 11 deletionspkg/github/repository_resource_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 {
Expand All@@ -258,26 +258,26 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
}
}

funcTest_getRepositoryResourceContent(t *testing.T) {
tmpl, _ :=getRepositoryResourceContent(nil, translations.NullTranslationHelper)
funcTest_GetRepositoryResourceContent(t *testing.T) {
tmpl, _ :=GetRepositoryResourceContent(nil, translations.NullTranslationHelper)
require.Equal(t, "repo://{owner}/{repo}/contents{/path*}", tmpl.URITemplate.Raw())
}

funcTest_getRepositoryResourceBranchContent(t *testing.T) {
tmpl, _ :=getRepositoryResourceBranchContent(nil, translations.NullTranslationHelper)
funcTest_GetRepositoryResourceBranchContent(t *testing.T) {
tmpl, _ :=GetRepositoryResourceBranchContent(nil, translations.NullTranslationHelper)
require.Equal(t, "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", tmpl.URITemplate.Raw())
}
funcTest_getRepositoryResourceCommitContent(t *testing.T) {
tmpl, _ :=getRepositoryResourceCommitContent(nil, translations.NullTranslationHelper)
funcTest_GetRepositoryResourceCommitContent(t *testing.T) {
tmpl, _ :=GetRepositoryResourceCommitContent(nil, translations.NullTranslationHelper)
require.Equal(t, "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", tmpl.URITemplate.Raw())
}

funcTest_getRepositoryResourceTagContent(t *testing.T) {
tmpl, _ :=getRepositoryResourceTagContent(nil, translations.NullTranslationHelper)
funcTest_GetRepositoryResourceTagContent(t *testing.T) {
tmpl, _ :=GetRepositoryResourceTagContent(nil, translations.NullTranslationHelper)
require.Equal(t, "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", tmpl.URITemplate.Raw())
}

funcTest_getRepositoryResourcePrContent(t *testing.T) {
tmpl, _ :=getRepositoryResourcePrContent(nil, translations.NullTranslationHelper)
funcTest_GetRepositoryResourcePrContent(t *testing.T) {
tmpl, _ :=GetRepositoryResourcePrContent(nil, translations.NullTranslationHelper)
require.Equal(t, "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", tmpl.URITemplate.Raw())
}
24 changes: 12 additions & 12 deletionspkg/github/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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))
Expand DownExpand Up@@ -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
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp