Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,24 @@ The following sets of tools are available:
- **get_me** - Get my user profile
- No parameters required

- **get_org_members** - Get organization members
- `org`: Organization login (owner) to get members for. (string, required)
- `page`: Page number for pagination (number, optional)
- `per_page`: Results per page (max 100) (number, optional)
- `role`: Filter by role: all, admin, member (string, optional)

- **get_team_members** - Get team members
- `org`: Organization login (owner) that contains the team. (string, required)
- `team_slug`: Team slug (string, required)

- **get_teams** - Get teams
- `user`: Username to get teams for. If not provided, uses the authenticated user. (string, optional)

- **list_outside_collaborators** - List outside collaborators
- `org`: The organization name (string, required)
- `page`: Page number for pagination (number, optional)
- `per_page`: Results per page (max 100) (number, optional)

</details>

<details>
Expand Down
32 changes: 32 additions & 0 deletions pkg/github/__toolsnaps__/get_org_members.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"annotations": {
"title": "Get organization members",
"readOnlyHint": true
},
"description": "Get member users of a specific organization. Returns a list of user objects with fields: login, id, avatar_url, type. Limited to organizations accessible with current credentials",
"inputSchema": {
"properties": {
"org": {
"description": "Organization login (owner) to get members for.",
"type": "string"
},
"page": {
"description": "Page number for pagination",
"type": "number"
},
"per_page": {
"description": "Results per page (max 100)",
"type": "number"
},
"role": {
"description": "Filter by role: all, admin, member",
"type": "string"
}
},
"required": [
"org"
],
"type": "object"
},
"name": "get_org_members"
}
28 changes: 28 additions & 0 deletions pkg/github/__toolsnaps__/list_outside_collaborators.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"annotations": {
"title": "List outside collaborators",
"readOnlyHint": true
},
"description": "List all outside collaborators of an organization (users with access to organization repositories but not members).",
"inputSchema": {
"properties": {
"org": {
"description": "The organization name",
"type": "string"
},
"page": {
"description": "Page number for pagination",
"type": "number"
},
"per_page": {
"description": "Results per page (max 100)",
"type": "number"
}
},
"required": [
"org"
],
"type": "object"
},
"name": "list_outside_collaborators"
}
189 changes: 189 additions & 0 deletions pkg/github/context_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package github

import (
"context"
"fmt"
"strings"
"time"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/go-viper/mapstructure/v2"
"github.com/google/go-github/v79/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/shurcooL/githubv4"
Expand Down Expand Up @@ -249,3 +253,188 @@ func GetTeamMembers(getGQLClient GetGQLClientFn, t translations.TranslationHelpe
return MarshalledTextResult(members), nil
}
}

func getOrgMembers(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
return mcp.NewTool("get_org_members",
mcp.WithDescription(t("TOOL_GET_ORG_MEMBERS_DESCRIPTION", "Get member users of a specific organization. Returns a list of user objects with fields: login, id, avatar_url, type. Limited to organizations accessible with current credentials")),
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool description claims to return "login, id, avatar_url, type" but the implementation also returns site_admin. The description should be updated to include site_admin in the list of returned fields for accuracy.

Suggested change
mcp.WithDescription(t("TOOL_GET_ORG_MEMBERS_DESCRIPTION", "Get member users of a specific organization. Returns a list of user objects with fields: login, id, avatar_url, type. Limited to organizations accessible with current credentials")),
mcp.WithDescription(t("TOOL_GET_ORG_MEMBERS_DESCRIPTION", "Get member users of a specific organization. Returns a list of user objects with fields: login, id, avatar_url, type, site_admin. Limited to organizations accessible with current credentials")),

Copilot uses AI. Check for mistakes.
mcp.WithString("org",
mcp.Description(t("TOOL_GET_ORG_MEMBERS_ORG_DESCRIPTION", "Organization login (owner) to get members for.")),
mcp.Required(),
),
mcp.WithString("role",
mcp.Description("Filter by role: all, admin, member"),
),
mcp.WithNumber("per_page",
mcp.Description("Results per page (max 100)"),
),
mcp.WithNumber("page",
mcp.Description("Page number for pagination"),
),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_GET_ORG_MEMBERS_TITLE", "Get organization members"),
ReadOnlyHint: ToBoolPtr(true),
}),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Decode params into struct to support optional numbers
var params struct {
Org string `mapstructure:"org"`
Role string `mapstructure:"role"`
PerPage int32 `mapstructure:"per_page"`
Page int32 `mapstructure:"page"`
}
if err := mapstructure.Decode(request.Params.Arguments, &params); err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
org := params.Org
role := params.Role
perPage := params.PerPage
page := params.Page
Comment on lines +297 to +300
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These intermediate variable assignments (lines 297-300) are unnecessary and reduce code clarity. The params struct fields (params.Org, params.Role, etc.) can be used directly throughout the function, which is the pattern followed by other tools in the codebase (e.g., GetDiscussion and GetDiscussionComments in discussions.go).

Copilot uses AI. Check for mistakes.
if org == "" {
return mcp.NewToolResultError("org is required"), nil
}

// Defaults
if perPage <= 0 {
perPage = 30
}
if perPage > 100 {
perPage = 100
}
if page <= 0 {
page = 1
}
client, err := getClient(ctx)
if err != nil {
return mcp.NewToolResultErrorFromErr("failed to get GitHub client", err), nil
}

// Map role string to REST role filter expected by GitHub API ("all","admin","member").
roleFilter := ""
if role != "" && strings.ToLower(role) != "all" {
roleFilter = strings.ToLower(role)
}

// Use Organizations.ListMembers with pagination (page/per_page)
opts := &github.ListMembersOptions{
Role: roleFilter,
ListOptions: github.ListOptions{
PerPage: int(perPage),
Page: int(page),
},
}

users, resp, err := client.Organizations.ListMembers(ctx, org, opts)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx, "Failed to get organization members", resp, err), nil
}

type outUser struct {
Login string `json:"login"`
ID string `json:"id"`
AvatarURL string `json:"avatar_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
}

var members []outUser
for _, u := range users {
members = append(members, outUser{
Login: u.GetLogin(),
ID: fmt.Sprintf("%v", u.GetID()),
AvatarURL: u.GetAvatarURL(),
Type: u.GetType(),
SiteAdmin: u.GetSiteAdmin(),
})
}

return MarshalledTextResult(members), nil
}
}

func listOutsideCollaborators(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
return mcp.NewTool("list_outside_collaborators",
mcp.WithDescription(t("TOOL_LIST_OUTSIDE_COLLABORATORS_DESCRIPTION", "List all outside collaborators of an organization (users with access to organization repositories but not members).")),
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool description should explicitly list all returned fields for consistency with other tools in the codebase. Consider adding "Returns a list of user objects with fields: login, id, avatar_url, type, site_admin" to match the pattern used in get_org_members and provide clarity about the response structure.

Suggested change
mcp.WithDescription(t("TOOL_LIST_OUTSIDE_COLLABORATORS_DESCRIPTION", "List all outside collaborators of an organization (users with access to organization repositories but not members).")),
mcp.WithDescription(t("TOOL_LIST_OUTSIDE_COLLABORATORS_DESCRIPTION", "List all outside collaborators of an organization (users with access to organization repositories but not members). Returns a list of user objects with fields: login, id, avatar_url, type, site_admin.")),

Copilot uses AI. Check for mistakes.
mcp.WithString("org",
mcp.Description(t("TOOL_LIST_OUTSIDE_COLLABORATORS_ORG_DESCRIPTION", "The organization name")),
mcp.Required(),
),
mcp.WithNumber("per_page",
mcp.Description("Results per page (max 100)"),
),
mcp.WithNumber("page",
mcp.Description("Page number for pagination"),
),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_OUTSIDE_COLLABORATORS_TITLE", "List outside collaborators"),
ReadOnlyHint: ToBoolPtr(true),
}),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Decode params into struct to support optional numbers
var params struct {
Org string `mapstructure:"org"`
PerPage int32 `mapstructure:"per_page"`
Page int32 `mapstructure:"page"`
}
if err := mapstructure.Decode(request.Params.Arguments, &params); err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
org := params.Org
perPage := params.PerPage
page := params.Page
Comment on lines +383 to +385
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These intermediate variable assignments (lines 383-385) are unnecessary and reduce code clarity. The params struct fields (params.Org, params.PerPage, params.Page) can be used directly throughout the function, which is the pattern followed by other tools in the codebase (e.g., GetDiscussion and GetDiscussionComments in discussions.go).

Copilot uses AI. Check for mistakes.
if org == "" {
return mcp.NewToolResultError("org is required"), nil
}

// Defaults
if perPage <= 0 {
perPage = 30
}
if perPage > 100 {
perPage = 100
}
if page <= 0 {
page = 1
}

client, err := getClient(ctx)
if err != nil {
return mcp.NewToolResultErrorFromErr("failed to get GitHub client", err), nil
}

// Use Organizations.ListOutsideCollaborators with pagination
opts := &github.ListOutsideCollaboratorsOptions{
ListOptions: github.ListOptions{
PerPage: int(perPage),
Page: int(page),
},
}

users, resp, err := client.Organizations.ListOutsideCollaborators(ctx, org, opts)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx, "Failed to list outside collaborators", resp, err), nil
}

type outUser struct {
Login string `json:"login"`
ID string `json:"id"`
AvatarURL string `json:"avatar_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
}

var collaborators []outUser
for _, u := range users {
collaborators = append(collaborators, outUser{
Login: u.GetLogin(),
ID: fmt.Sprintf("%v", u.GetID()),
AvatarURL: u.GetAvatarURL(),
Type: u.GetType(),
SiteAdmin: u.GetSiteAdmin(),
})
}

return MarshalledTextResult(collaborators), nil
}
}
Loading