MCPcopy Index your code
hub / github.com/github/github-mcp-server / uiGetLabels

Function uiGetLabels

pkg/github/ui_tools.go:106–179  ·  view source on GitHub ↗
(ctx context.Context, deps ToolDependencies, args map[string]any, owner string)

Source from the content-addressed store, hash-verified

104}
105
106func uiGetLabels(ctx context.Context, deps ToolDependencies, args map[string]any, owner string) (*mcp.CallToolResult, any, error) {
107 repo, err := RequiredParam[string](args, "repo")
108 if err != nil {
109 return utils.NewToolResultError(err.Error()), nil, nil
110 }
111
112 client, err := deps.GetGQLClient(ctx)
113 if err != nil {
114 return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
115 }
116
117 var query struct {
118 Repository struct {
119 Labels struct {
120 Nodes []struct {
121 ID githubv4.ID
122 Name githubv4.String
123 Color githubv4.String
124 Description githubv4.String
125 }
126 TotalCount githubv4.Int
127 PageInfo struct {
128 HasNextPage githubv4.Boolean
129 EndCursor githubv4.String
130 }
131 } `graphql:"labels(first: 100, after: $cursor)"`
132 } `graphql:"repository(owner: $owner, name: $repo)"`
133 }
134
135 vars := map[string]any{
136 "owner": githubv4.String(owner),
137 "repo": githubv4.String(repo),
138 "cursor": (*githubv4.String)(nil),
139 }
140
141 labels := make([]map[string]any, 0)
142 var totalCount int
143 hasMore := false
144 for page := 1; ; page++ {
145 if err := client.Query(ctx, &query, vars); err != nil {
146 return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to list labels", err), nil, nil
147 }
148 for _, labelNode := range query.Repository.Labels.Nodes {
149 labels = append(labels, map[string]any{
150 "id": fmt.Sprintf("%v", labelNode.ID),
151 "name": string(labelNode.Name),
152 "color": string(labelNode.Color),
153 "description": string(labelNode.Description),
154 })
155 }
156 totalCount = int(query.Repository.Labels.TotalCount)
157 if !query.Repository.Labels.PageInfo.HasNextPage {
158 break
159 }
160 if page >= uiGetMaxPages {
161 hasMore = true
162 break
163 }

Callers 1

UIGetFunction · 0.85

Calls 5

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
GetGQLClientMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected