- Notifications
You must be signed in to change notification settings - Fork3.1k
feat: add list repository contributors and update readme#893
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
base:main
Are you sure you want to change the base?
Changes fromall commits
e6109f9ece480efb3b435f90c545da07dce056623dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "annotations": { | ||
| "title": "List repository contributors", | ||
| "readOnlyHint": true | ||
| }, | ||
| "description": "Get list of contributors for a GitHub repository. Returns at least 30 results per page by default, but can return more if specified using the perPage parameter (up to 100).", | ||
| "inputSchema": { | ||
| "properties": { | ||
| "owner": { | ||
| "description": "Repository owner", | ||
| "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" | ||
| }, | ||
| "repo": { | ||
| "description": "Repository name", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "owner", | ||
| "repo" | ||
| ], | ||
| "type": "object" | ||
| }, | ||
| "name": "list_repository_contributors" | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -200,6 +200,76 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| // ListRepositoryContributors creates a tool to get contributors of a repository. | ||||||||||||||||
| func ListRepositoryContributors(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||||||||||||||||
| return mcp.NewTool("list_repository_contributors", | ||||||||||||||||
| mcp.WithDescription(t("TOOL_LIST_REPOSITORY_CONTRIBUTORS_DESCRIPTION", "Get list of contributors for a GitHub repository. 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_REPOSITORY_CONTRIBUTORS_USER_TITLE", "List repository contributors"), | ||||||||||||||||
| 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.ListContributorsOptions{ | ||||||||||||||||
| ListOptions: 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) | ||||||||||||||||
| } | ||||||||||||||||
| contributors, resp, err := client.Repositories.ListContributors(ctx, owner, repo, opts) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||||||||||||||||
| fmt.Sprintf("failed to list contributors for repository: %s/%s", owner, repo), | ||||||||||||||||
| resp, | ||||||||||||||||
| err, | ||||||||||||||||
| ), nil | ||||||||||||||||
| } | ||||||||||||||||
| 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 contributors: %s", string(body))), nil | ||||||||||||||||
| } | ||||||||||||||||
Comment on lines +256 to +263 CopilotAI | ||||||||||||||||
| ifresp.StatusCode!= http.StatusOK { | |
| body,err:=io.ReadAll(resp.Body) | |
| iferr!=nil { | |
| returnnil,fmt.Errorf("failed to read response body: %w",err) | |
| } | |
| returnmcp.NewToolResultError(fmt.Sprintf("failed to list contributors: %s",string(body))),nil | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # Test script for list_repository_contributors function | ||
| # Usage: ./script/list-repository-contributors <owner> <repo> | ||
| if [ $# -ne 2 ]; then | ||
| echo "Usage: $0 <owner> <repo>" | ||
| echo "Example: $0 octocat Hello-World" | ||
| exit 1 | ||
| fi | ||
| OWNER=$1 | ||
| REPO=$2 | ||
| echo "Testing list_repository_contributors for $OWNER/$REPO" | ||
| echo "{\"jsonrpc\":\"2.0\",\"id\":1,\"params\":{\"name\":\"list_repository_contributors\",\"arguments\":{\"owner\":\"$OWNER\",\"repo\":\"$REPO\"}},\"method\":\"tools/call\"}" | go run cmd/github-mcp-server/main.go stdio | jq . |