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

Feat: Add support for GitHub Releases (list and latest) tools#469

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

Open
aryasoni98 wants to merge9 commits intogithub:main
base:main
Choose a base branch
Loading
fromaryasoni98:issue-461
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
9 commits
Select commitHold shift + click to select a range
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
74 changes: 65 additions & 9 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,8 +16,67 @@ automation and interaction capabilities for developers and tools.

1. To run the server in a container, you will need to have [Docker](https://www.docker.com/) installed.
2. Once Docker is installed, you will also need to ensure Docker is running. The image is public; if you get errors on pull, you may have an expired token and need to `docker logout ghcr.io`.
3. Lastly you will need to [Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
The MCP server can use many of the GitHub APIs, so enable the permissions that you feel comfortable granting your AI tools (to learn more about access tokens, please check out the [documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)).
3. [Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
Each tool requires specific permissions to function. See the [Required Token Permissions](#required-token-permissions) section below for details.

## Required Token Permissions

Each tool requires specific GitHub Personal Access Token permissions to function. Below are the required permissions for each tool category:

### Users
- **get_me**
- Required permissions:
- `read:user` - Read access to profile info

### Issues
- **get_issue**, **get_issue_comments**, **list_issues**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)

- **create_issue**, **add_issue_comment**, **update_issue**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)
- `write:discussion` - Write access to repository discussions (if using discussions)

### Pull Requests
- **get_pull_request**, **list_pull_requests**, **get_pull_request_files**, **get_pull_request_status**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)

- **merge_pull_request**, **update_pull_request_branch**, **create_pull_request**, **update_pull_request**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)
- `write:discussion` - Write access to repository discussions (if using discussions)

### Repositories
- **get_file_contents**, **search_repositories**, **list_commits**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)

- **create_or_update_file**, **push_files**, **create_repository**, **fork_repository**, **create_branch**
- Required permissions:
- `repo` - Full control of private repositories (for private repos)
- `public_repo` - Access public repositories (for public repos)
- `delete_repo` - Delete repositories (if needed)

### Search
- **search_code**, **search_users**
- Required permissions:
- No special permissions required for public data
- `repo` - Required for searching private repositories

### Code Scanning
- **get_code_scanning_alert**, **list_code_scanning_alerts**
- Required permissions:
- `security_events` - Read and write security events
- `repo` - Full control of private repositories (for private repos)

Note: For organization repositories, additional organization-specific permissions may be required.

## Installation

Expand DownExpand Up@@ -477,12 +536,6 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
- `branch`: Branch name (string, optional)
- `sha`: File SHA if updating (string, optional)

- **list_branches** - List branches in a GitHub repository
- `owner`: Repository owner (string, required)
- `repo`: Repository name (string, required)
- `page`: Page number (number, optional)
- `perPage`: Results per page (number, optional)

- **push_files** - Push multiple files in a single commit
- `owner`: Repository owner (string, required)
- `repo`: Repository name (string, required)
Expand DownExpand Up@@ -520,7 +573,7 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
- `branch`: New branch name (string, required)
- `sha`: SHA to create branch from (string, required)

- **list_commits** -Get a list of commits of a branch in a repository
- **list_commits** -Gets commits of a branch in a repository
- `owner`: Repository owner (string, required)
- `repo`: Repository name (string, required)
- `sha`: Branch name, tag, or commit SHA (string, optional)
Expand All@@ -535,6 +588,8 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
- `page`: Page number, for files in the commit (number, optional)
- `perPage`: Results per page, for files in the commit (number, optional)

### Search

- **search_code** - Search for code across GitHub repositories
- `query`: Search query (string, required)
- `sort`: Sort field (string, optional)
Expand DownExpand Up@@ -675,3 +730,4 @@ The exported Go API of this module should currently be considered unstable, and
## License

This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE) for the full terms.

120 changes: 120 additions & 0 deletionspkg/github/repositories.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1100,3 +1100,123 @@ func GetTag(getClient GetClientFn, t translations.TranslationHelperFunc) (tool m
return mcp.NewToolResultText(string(r)), nil
}
}

// ListReleases creates a tool to list releases in a GitHub repository.
func ListReleases(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_releases",
mcp.WithDescription(t("TOOL_LIST_RELEASES_DESCRIPTION", "List releases in a GitHub repository")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_RELEASES_USER_TITLE", "List releases"),
ReadOnlyHint: toBoolPtr(true),
}),
mcp.WithString("owner",
mcp.Required(),
mcp.Description("Repository owner"),
),
mcp.WithString("repo",
mcp.Required(),
mcp.Description("Repository name"),
),
WithPagination(),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := requiredParam[string](request, "owner")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
repo, err := requiredParam[string](request, "repo")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
pagination, err := OptionalPaginationParams(request)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

opts := &github.ListOptions{
Page: pagination.page,
PerPage: pagination.perPage,
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

releases, resp, err := client.Repositories.ListReleases(ctx, owner, repo, opts)
if err != nil {
return nil, fmt.Errorf("failed to list releases: %w", err)
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
return mcp.NewToolResultError(fmt.Sprintf("failed to list releases: %s", string(body))), nil
}

r, err := json.Marshal(releases)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
}

return mcp.NewToolResultText(string(r)), nil
}
}

// GetLatestRelease creates a tool to get the latest release in a GitHub repository.
func GetLatestRelease(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("get_latest_release",
mcp.WithDescription(t("TOOL_GET_LATEST_RELEASE_DESCRIPTION", "Get the latest release in a GitHub repository")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_GET_LATEST_RELEASE_USER_TITLE", "Get latest release"),
ReadOnlyHint: toBoolPtr(true),
}),
mcp.WithString("owner",
mcp.Required(),
mcp.Description("Repository owner"),
),
mcp.WithString("repo",
mcp.Required(),
mcp.Description("Repository name"),
),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := requiredParam[string](request, "owner")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
repo, err := requiredParam[string](request, "repo")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

release, resp, err := client.Repositories.GetLatestRelease(ctx, owner, repo)
if err != nil {
return nil, fmt.Errorf("failed to get latest release: %w", err)
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
return mcp.NewToolResultError(fmt.Sprintf("failed to get latest release: %s", string(body))), nil
}

r, err := json.Marshal(release)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
}

return mcp.NewToolResultText(string(r)), nil
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp