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

Function ListBranches

pkg/github/repositories.go:288–377  ·  view source on GitHub ↗

ListBranches creates a tool to list branches in a GitHub repository.

(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

286
287// ListBranches creates a tool to list branches in a GitHub repository.
288func ListBranches(t translations.TranslationHelperFunc) inventory.ServerTool {
289 return NewTool(
290 ToolsetMetadataRepos,
291 mcp.Tool{
292 Name: "list_branches",
293 Description: t("TOOL_LIST_BRANCHES_DESCRIPTION", "List branches in a GitHub repository"),
294 Annotations: &mcp.ToolAnnotations{
295 Title: t("TOOL_LIST_BRANCHES_USER_TITLE", "List branches"),
296 ReadOnlyHint: true,
297 },
298 InputSchema: WithPagination(&jsonschema.Schema{
299 Type: "object",
300 Properties: map[string]*jsonschema.Schema{
301 "owner": {
302 Type: "string",
303 Description: "Repository owner",
304 },
305 "repo": {
306 Type: "string",
307 Description: "Repository name",
308 },
309 },
310 Required: []string{"owner", "repo"},
311 }),
312 },
313 []scopes.Scope{scopes.Repo},
314 func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
315 owner, err := RequiredParam[string](args, "owner")
316 if err != nil {
317 return utils.NewToolResultError(err.Error()), nil, nil
318 }
319 repo, err := RequiredParam[string](args, "repo")
320 if err != nil {
321 return utils.NewToolResultError(err.Error()), nil, nil
322 }
323 pagination, err := OptionalPaginationParams(args)
324 if err != nil {
325 return utils.NewToolResultError(err.Error()), nil, nil
326 }
327
328 opts := &github.BranchListOptions{
329 ListOptions: github.ListOptions{
330 Page: pagination.Page,
331 PerPage: pagination.PerPage,
332 },
333 }
334
335 client, err := deps.GetClient(ctx)
336 if err != nil {
337 return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
338 }
339
340 branches, resp, err := client.Repositories.ListBranches(ctx, owner, repo, opts)
341 if err != nil {
342 return ghErrors.NewGitHubAPIErrorResponse(ctx,
343 "failed to list branches",
344 resp,
345 err,

Callers 2

AllToolsFunction · 0.85
Test_ListBranchesFunction · 0.85

Calls 10

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
NewToolFunction · 0.85
WithPaginationFunction · 0.85
OptionalPaginationParamsFunction · 0.85
convertToMinimalBranchFunction · 0.85
CloseMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.45

Tested by 1

Test_ListBranchesFunction · 0.68