MCPcopy
hub / github.com/github/github-mcp-server / GetTeams

Function GetTeams

pkg/github/context_tools.go:126–227  ·  view source on GitHub ↗
(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

124}
125
126func GetTeams(t translations.TranslationHelperFunc) inventory.ServerTool {
127 return NewTool(
128 ToolsetMetadataContext,
129 mcp.Tool{
130 Name: "get_teams",
131 Description: t("TOOL_GET_TEAMS_DESCRIPTION", "Get details of the teams the user is a member of. Limited to organizations accessible with current credentials"),
132 Annotations: &mcp.ToolAnnotations{
133 Title: t("TOOL_GET_TEAMS_TITLE", "Get teams"),
134 ReadOnlyHint: true,
135 },
136 InputSchema: &jsonschema.Schema{
137 Type: "object",
138 Properties: map[string]*jsonschema.Schema{
139 "user": {
140 Type: "string",
141 Description: t("TOOL_GET_TEAMS_USER_DESCRIPTION", "Username to get teams for. If not provided, uses the authenticated user."),
142 },
143 },
144 },
145 },
146 []scopes.Scope{scopes.ReadOrg},
147 func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
148 user, err := OptionalParam[string](args, "user")
149 if err != nil {
150 return utils.NewToolResultError(err.Error()), nil, nil
151 }
152
153 var username string
154 if user != "" {
155 username = user
156 } else {
157 client, err := deps.GetClient(ctx)
158 if err != nil {
159 return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
160 }
161
162 userResp, res, err := client.Users.Get(ctx, "")
163 if err != nil {
164 return ghErrors.NewGitHubAPIErrorResponse(ctx,
165 "failed to get user",
166 res,
167 err,
168 ), nil, nil
169 }
170 username = userResp.GetLogin()
171 }
172
173 gqlClient, err := deps.GetGQLClient(ctx)
174 if err != nil {
175 return utils.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil, nil
176 }
177
178 var q struct {
179 User struct {
180 Organizations struct {
181 Nodes []struct {
182 Login githubv4.String
183 Teams struct {

Callers 2

AllToolsFunction · 0.85
Test_GetTeamsFunction · 0.85

Calls 10

NewToolResultErrorFunction · 0.92
LabelTeamFunction · 0.92
NewToolFunction · 0.85
MarshalledTextResultFunction · 0.85
attachStaticIFCLabelFunction · 0.85
GetClientMethod · 0.65
GetGQLClientMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by 1

Test_GetTeamsFunction · 0.68