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 list_starred_repositories tool#815

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

Closed
Closed
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
7 changes: 7 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -848,6 +848,13 @@ The following sets of tools are available (all are on by default):
- `repo`: Repository name (string, required)
- `sha`: Commit SHA, branch or tag name to list commits of. If not provided, uses the default branch of the repository. If a commit SHA is provided, will list commits up to that SHA. (string, optional)

- **list_starred_repositories** - List starred repositories
- `direction`: Direction to sort repositories. Can be 'asc' or 'desc'. Default is 'desc'. (string, optional)
- `page`: Page number for pagination (min 1) (number, optional)
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
- `sort`: Sort order for repositories. Can be 'created' (when the repository was starred) or 'updated' (when the repository was last pushed to). Default is 'created'. (string, optional)
- `username`: GitHub username of the user whose starred repositories to list (string, required)

- **list_tags** - List tags
- `owner`: Repository owner (string, required)
- `page`: Page number for pagination (min 1) (number, optional)
Expand Down
47 changes: 47 additions & 0 deletionspkg/github/__toolsnaps__/list_starred_repositories.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
{
"annotations": {
"title": "List starred repositories",
"readOnlyHint": true
},
"description": "List repositories that a user has starred on GitHub. Returns at least 30 results per page by default, but can return more if specified using the perPage parameter (up to 100).",
"inputSchema": {
"properties": {
"direction": {
"description": "Direction to sort repositories. Can be 'asc' or 'desc'. Default is 'desc'.",
"enum": [
"asc",
"desc"
],
"type": "string"
},
"page": {
"description": "Page number for pagination (min 1)",
"minimum": 1,
"type": "number"
},
"perPage": {
"description": "Results per page for pagination (min 1, max 100)",
"maximum": 100,
"minimum": 1,
"type": "number"
},
"sort": {
"description": "Sort order for repositories. Can be 'created' (when the repository was starred) or 'updated' (when the repository was last pushed to). Default is 'created'.",
"enum": [
"created",
"updated"
],
"type": "string"
},
"username": {
"description": "GitHub username of the user whose starred repositories to list",
"type": "string"
}
},
"required": [
"username"
],
"type": "object"
},
"name": "list_starred_repositories"
}
91 changes: 91 additions & 0 deletionspkg/github/starred_repos.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
package github

import (
"context"
"encoding/json"
"fmt"

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v73/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)

// ListStarredRepositories creates a tool to list repositories that a user has starred.
func ListStarredRepositories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_starred_repositories",
mcp.WithDescription(t("TOOL_LIST_STARRED_REPOSITORIES_DESCRIPTION", "List repositories that a user has starred on GitHub. Returns at least 30 results per page by default, but can return more if specified using the perPage parameter (up to 100).")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_STARRED_REPOSITORIES_USER_TITLE", "List starred repositories"),
ReadOnlyHint: ToBoolPtr(true),
}),
mcp.WithString("username",
mcp.Required(),
mcp.Description("GitHub username of the user whose starred repositories to list"),
),
mcp.WithString("sort",
mcp.Description("Sort order for repositories. Can be 'created' (when the repository was starred) or 'updated' (when the repository was last pushed to). Default is 'created'."),
mcp.Enum("created", "updated"),
),
mcp.WithString("direction",
mcp.Description("Direction to sort repositories. Can be 'asc' or 'desc'. Default is 'desc'."),
mcp.Enum("asc", "desc"),
),
WithPagination(),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
username, err := RequiredParam[string](request, "username")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
sort, err := OptionalParam[string](request, "sort")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
direction, err := OptionalParam[string](request, "direction")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
pagination, err := OptionalPaginationParams(request)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

perPage := pagination.PerPage
if perPage == 0 {
perPage = 30
}

page := pagination.Page
if page == 0 {
page = 1
}

opts := &github.ActivityListStarredOptions{
Sort: sort,
Direction: direction,
ListOptions: github.ListOptions{
Page: page,
PerPage: perPage,
},
}

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

starredRepos, resp, err := client.Activity.ListStarred(ctx, username, opts)
if err != nil {
return nil, fmt.Errorf("failed to list starred repositories for user: %s: %w", username, err)
}
defer func() { _ = resp.Body.Close() }()

r, err := json.Marshal(starredRepos)
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