Skip to content

Commit b28d98b

Browse files
committed
flatten teams response to not include Nodes
1 parent 8a332fc commit b28d98b

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

pkg/github/context_tools.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too
9494
}
9595

9696
func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
97+
type TeamInfo struct {
98+
Name string `json:"name"`
99+
Slug string `json:"slug"`
100+
Description string `json:"description"`
101+
}
102+
103+
type OrganizationTeams struct {
104+
Login string `json:"login"`
105+
Teams []TeamInfo `json:"teams"`
106+
}
107+
97108
tool := mcp.NewTool("get_teams",
98109
mcp.WithDescription(t("TOOL_GET_TEAMS_DESCRIPTION", "Get details of the teams the user is a member of")),
99110
mcp.WithString("user",
@@ -157,7 +168,25 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations
157168
return mcp.NewToolResultError(err.Error()), nil
158169
}
159170

160-
return MarshalledTextResult(q.User.Organizations.Nodes), nil
171+
var organizations []OrganizationTeams
172+
for _, org := range q.User.Organizations.Nodes {
173+
orgTeams := OrganizationTeams{
174+
Login: string(org.Login),
175+
Teams: make([]TeamInfo, 0, len(org.Teams.Nodes)),
176+
}
177+
178+
for _, team := range org.Teams.Nodes {
179+
orgTeams.Teams = append(orgTeams.Teams, TeamInfo{
180+
Name: string(team.Name),
181+
Slug: string(team.Slug),
182+
Description: string(team.Description),
183+
})
184+
}
185+
186+
organizations = append(organizations, orgTeams)
187+
}
188+
189+
return MarshalledTextResult(organizations), nil
161190
})
162191

163192
return tool, handler

pkg/github/context_tools_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,10 @@ func Test_GetTeams(t *testing.T) {
347347

348348
var organizations []struct {
349349
Login string `json:"login"`
350-
Teams struct {
351-
Nodes []struct {
352-
Name string `json:"name"`
353-
Slug string `json:"slug"`
354-
Description string `json:"description"`
355-
} `json:"nodes"`
350+
Teams []struct {
351+
Name string `json:"name"`
352+
Slug string `json:"slug"`
353+
Description string `json:"description"`
356354
} `json:"teams"`
357355
}
358356
err = json.Unmarshal([]byte(textContent.Text), &organizations)
@@ -362,14 +360,17 @@ func Test_GetTeams(t *testing.T) {
362360

363361
if tc.expectedTeamsCount > 0 {
364362
assert.Equal(t, "testorg1", organizations[0].Login)
365-
assert.Len(t, organizations[0].Teams.Nodes, 2)
366-
assert.Equal(t, "team1", organizations[0].Teams.Nodes[0].Name)
367-
assert.Equal(t, "team1", organizations[0].Teams.Nodes[0].Slug)
363+
assert.Len(t, organizations[0].Teams, 2)
364+
assert.Equal(t, "team1", organizations[0].Teams[0].Name)
365+
assert.Equal(t, "team1", organizations[0].Teams[0].Slug)
366+
assert.Equal(t, "Team 1", organizations[0].Teams[0].Description)
368367

369368
if tc.expectedTeamsCount > 1 {
370369
assert.Equal(t, "testorg2", organizations[1].Login)
371-
assert.Len(t, organizations[1].Teams.Nodes, 1)
372-
assert.Equal(t, "team3", organizations[1].Teams.Nodes[0].Name)
370+
assert.Len(t, organizations[1].Teams, 1)
371+
assert.Equal(t, "team3", organizations[1].Teams[0].Name)
372+
assert.Equal(t, "team3", organizations[1].Teams[0].Slug)
373+
assert.Equal(t, "Team 3", organizations[1].Teams[0].Description)
373374
}
374375
}
375376
})

0 commit comments

Comments
 (0)