- Notifications
You must be signed in to change notification settings - Fork3.1k
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
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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 | ||
| } | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.