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) {
Comment thread
cointem marked this conversation as resolved.
Outdated
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")),
Comment thread
cointem marked this conversation as resolved.
Outdated
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 thread
cointem marked this conversation as resolved.
Outdated
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"`
}
Comment thread
cointem marked this conversation as resolved.
Outdated

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) {
Comment thread
cointem marked this conversation as resolved.
Outdated
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).")),
Comment thread
cointem marked this conversation as resolved.
Outdated
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 thread
cointem marked this conversation as resolved.
Outdated
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